title: synchronized LinkedList in Java
body: <p>when I have two LinkedLists, product and price declared on the top of a class. And there are some threads who can write to this lists, I must(!) safe this Lists with a Mutex (synchronized). Is the following correct and is there a better way?</p>
  
  <pre><code>public class Shop extends Thread {
    volatile LinkedList&lt;String&gt; product = new LinkedList&lt;String&gt;();
    volatile LinkedList&lt;Float&gt; price = new LinkedList&lt;Integer&gt;();
  
    public class Inserter extends Thread {
     @Override
     public void run() {
      synchronized (product) {
       product.add(i1);
      }
  
      synchronized (price) {
       price.add(i2);
      }
     }
    }
  }
  </code></pre>