title: Java Multithreading large arrays access
body: <p>My main class, generates multiple threads based on some rules. (20-40 threads live for long time).
  Each thread create several threads (short time ) --> I am using executer for this one.
  I need to work on  Multi dimension arrays in the short time threads --> I wrote it like it is in the code below --> but I think that it is not efficient since I pass it so many times to so many threads / tasks --. I tried to access it directly from the threads (by declaring it as public --> no success) --> will be happy to get comments / advices on how to improve it.
  I also look at next step to return a 1 dimension array as a result (which might be better just to update it at the Assetfactory class ) --> and I am not sure how to.
  please see the code below.
  thanks
  Paz</p>
  
  <pre><code>import java.util.concurrent.*;
  import java.util.logging.Level;
  
  public class AssetFactory implements Runnable{
      private volatile boolean stop = false;
      private volatile String feed ;
      private double[][][] PeriodRates= new double[10][500][4];
  
      private String TimeStr,Bid,periodicalRateIndicator;
      private final BlockingQueue&lt;String&gt; workQueue;
      ExecutorService IndicatorPool = Executors.newCachedThreadPool();
  
      public AssetFactory(BlockingQueue&lt;String&gt; workQueue) {
        this.workQueue = workQueue;
      }   
  
      @Override
      public void run(){
        while (!stop) {
         try{   
            feed = workQueue.take(); 
              periodicalRateIndicator = CheckPeriod(TimeStr, Bid) ;
              if (periodicalRateIndicator.length() &gt;0) {
                  IndicatorPool.submit(new CalcMvg(periodicalRateIndicator,PeriodRates));
              } 
  
            } 
  
            if ("Stop".equals(feed)) {
                stop = true ;
            }
  
         } // try
         catch (InterruptedException ex) {
             logger.log(Level.SEVERE, null, ex);
             stop = true;
         }
  
  
        } // while
      } // run  
  </code></pre>
  
  <p>Here is the CalcMVG class</p>
  
  <pre><code>public class CalcMvg implements Runnable {
      private double [][][] PeriodRates = new double[10][500][4];
  
      public CalcMvg(String Periods, double[][][] PeriodRates) {
          System.out.println(Periods); 
          this.PeriodRates = PeriodRates ;
      }
  
      @Override
      public void run(){
         try{
            // do some work with the data of PeriodRates array e.g. print it (no changes to array
            System.out.println(PeriodRates[1][1][1]);
            }
         catch (Exception ex){
            System.out.println(Thread.currentThread().getName() + ex.getMessage());
            logger.log(Level.SEVERE, null, ex);
           }
        }//run
  
    } // mvg class
  </code></pre>