title: Passing a local new object to a thread, thread safe?
body: <p>I have a method (example below) which creates a new list, puts some stuff into it, and passes it along to another thread to operate on.</p>
  
  <p>This seems thread safe. The list is local to the method which creates it. The method operates on the list and doesn't pass it to another thread until it is done operating on it.</p>
  
  <p>But this <em>feels</em> wrong, because the list is accessed in two separate threads but it is not synchronized.</p>
  
  <p>Is this acceptable thread-safe code?</p>
  
  <pre><code>class App
  {
    public static void main(String[] args)
    {
      final ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      list.add(4);
      list.add(5);
  
      final ExecutorService es = Executors.newSingleThreadExecutor();
      es.execute(new Runnable() {
          @Override public void run()
          {
            for (Integer i : list)
              System.out.println(i);
          }});
      es.shutdown();
    }
  }
  </code></pre>