title: Sharing a ThreadLocal variable in Java
body: <p>In my small application I have threads of two classes - basically writers and readers. Multiple readers can be assigned to a single writer. A writer interacts with its readers by writing to their <code>chunkBuffer</code> variable.</p>
  
  <p>Now, I can't quite wrap my head around the thread safety issue here: if I do not store the <code>chunkBuffer</code> in a static <code>ThreadLocal</code> variable, all readers will share a single chunkBuffer, which is bad. But if I do store the chunkBuffer in a static <code>ThreadLocal</code>, the writer, being a separate thread, will get its own copy of the chunkBuffer and will keep writing to it, while none of the data it writes will reach the readers. Can you explain to me what's the problem here? Thank you very much.</p>
  
  <p><strong>Edit</strong> In other words, is there a way to create a field that will be unique for every single instance of a thread subclass (like ThreadLocal), but can be accessed from other threads on demand?</p>