How to share Hashmap between threads in Java?
<p>I am getting empty hashmap when I print it, what's the best approach to Share Static volatile variable between threads?</p>

<pre><code>class RunnableDemo implements Runnable {
      int i;
      RunnableDemo(int i) {
          i = i;
      }

      public void run(){
         finResult.put("value"+str(i), 1);
      } 

      public void start () {
          System.out.println("Starting " );
          if (t == null) {
             t = new Thread (this);
             t.start ();
      }
}

public class TestThread {
    public static volatile ConcurrentHashMap&lt;String, Integer&gt; finResult = new ConcurrentHashMap&lt;String, Integer&gt;();

    public static void main(String args[]) {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
        for(int i=0; i &lt; 4; i++){
            RunnableDemo task = new RunnableDemo(i);
            executor.execute(task);
        }
        executor.shutdown();
    }
    System.out.println(TestThread.finResult);
} 
</code></pre>

<p><code>System.out.println(TestThread.finResult);</code> This should print the finResult with all the values from threads. </p>