title: share an instance but create new one for every new process
body: <p>here is my problem--</p>
  
  <p>I have 4 classes - Starter , Database and Scheduler and a Test class.</p>
  
  <p>Test class will create a new instance of Starter (which loads and starts the entire process).
  Starter initializes Scheduler and Database classes.</p>
  
  <p>Test class passes a data to Starter. Starter stores it in a HashMap in Database class.
  Scheduler reads the <strong>same</strong> HashMap from Database class.</p>
  
  <p>Now to ensure that the exact same HashMap is access by all classes throughout my java project, I have 2 options-- to make HashMap <strong>static</strong> or to make Database  a <strong>singleton class</strong>. I have made Database a singleton class for now.</p>
  
  <p>The problem-- if Test class does this</p>
  
  <p>Starter starterInstance1 = new Starter();</p>
  
  <p>Starter starterInstance2 = new Starter();</p>
  
  <p>how do i ensure starterInstance1 and starterInstance2 have their own instance of Database class or the HashMap?</p>
  
  <p>==========</p>
  
  <p>Just being more clear:</p>
  
  <p>class Test{</p>
  
  <p>Starter start1 = new Starter();//creating 1 instance of my application</p>
  
  <p>start1.init();//this will initialize Scheduler etc and do a "getDatabaseInstance()"</p>
  
  <p>for(int i=0;i&lt;50;i++){</p>
  
  <p>start1.sendData("abc");
  //all these 50 requests will b submitted to a threadpool that will send request to be stored in HashMap in Database class. The HashMap will be accessed concurrently by Scheduler and other classes. I have made the Database class singleton so that all classes will be accessing the same instance of DB.</p>
  
  <p>}</p>
  
  <p>//Similarly creating another instance of my application</p>
  
  <p>Starter start2 = new Starter();</p>
  
  <p>start2.init();//now here if I do "getDatabaseInstance()", i will get the same instance as above. but i want a separate Database for this instance of application. how do i achieve this?</p>
  
  <p>for(int i=0;i&lt;50;i++){</p>
  
  <p>start2.sendData("abc");</p>
  
  <p>}</p>
  
  <p>}</p>