title: Passing a work item between threads (Java)
body: <p>I have two threads. The producer is producing pieces of data (String objects), where the consumer processes these strings. The catch is that my application only needs the most recent data object to be processed. In other words, if the producer managed to produce two strings "s1" and then "s2" then I want the consumer to process only "s2". "s1" can be safely discarded.</p>
  
  <p>Of course there's no problem implementing a class that realizes this behavior, but I want to use a standard mechanism from java.util.concurrent (if such a mechanism exists). Note that  SynchronousQueue is not a good solution: the consumer will block when enqueueing "s1" and will not get the chance to produce "s2".</p>
  
  <p>(In short, I am looking for a single-element collection with a blocking remove operation and a non-blocking set operation)</p>
  
  <p>Any ideas?</p>