title: java static variables and cache
body: <p>I have two threads and they are both reading the same static variable (some big object - an array with 500_000_000 ints).</p>
  
  <p>The two threads are pinned to a cpu (1 and 2) (cpu affinity) so minimize jitters. </p>
  
  <p>Do you know if the two threads will slow down each other because of the static variable is read by both threads running on different cpu? </p>
  
  <pre><code>import net.openhft.affinity.AffinityLock;
  
  public class BigObject {
      public final int[] array = new int[500_000_000];
      public static final  BigObject bo_static = new BigObject();
  
      public BigObject() {
          for( int i = 0; i&lt;array.length; i++){
              array[i]=i;
          }
      }
  
      public static void main(String[] args) {
          final Boolean useStatic = true;
          Integer n = 2;
          for( int i = 0; i&lt;n; i++){
              final int k = i;    
              Runnable r = new Runnable() {
                  @Override
                  public void run() {
                      BigObject b;
                      if( useStatic){
                          b = BigObject.bo_static;
                      }
                      else{
                          b = new BigObject();
                      }
                      try (AffinityLock al = AffinityLock.acquireLock()) {
                          while(true){
                              long nt1 = System.nanoTime();
                              double sum = 0;
                              for( int i : b.array){
                                  sum+=i;
                              }
                              long nt2 = System.nanoTime();
                              double dt = (nt2-nt1)*1e-6;
                              System.out.println(k + ": sum " + sum + " " + dt);
                          }
                      }
                  }
              };
              new Thread(r).start();
          }
      }   
  }
  </code></pre>
  
  <p>Thanks</p>