title: What synchronization primitive should I use to implement a event driver framework in Java?
body: <p>I have a looper thread to execute tasks. Other threads can submit tasks to this looper thread. Some tasks are immediate tasks, others are future tasks, which are to be executed after T seconds after submission. I use <code>PriorityBlockingQueue</code> to store tasks, where time is used as the priority, so that the first task of the queue is the most imminent task to be executed.</p>
  
  <p>The looper's main loop is as fellows:</p>
  
  <pre><code>PriorityBlockingQueue&lt;Event&gt; taskQueue = ...
  while (true) {
      if (taskQueue.isEmpty())
          &lt;something&gt;.wait(); // wait indefinitely
      else
          &lt;something&gt;.wait(taskQueue.peek().time - NOW()); // wait for the first task
      Task task = taskQueue.poll(0); // take the first task without waiting
      if (task != null &amp;&amp; task.time &lt;= NOW())
          task.execute();
      else if (task != null)
          taskQueue.offer(task); // not yet runnable, put it back
  }
  </code></pre>
  
  <p>The looper provides allows other threads (or itself) to submit tasks:</p>
  
  <pre><code>public void submitTask (Task task) { // time information is contained in the task.
      taskQueue.offer(task);
      &lt;something&gt;.signal(); // informs the loop thread that new task is avaliable.
  }
  </code></pre>
  
  <p>Here, I have only one thread calling <code>wait()</code> and multiple threads calling <code>signal()</code>. My question is that what synchronization primitive should I use in the place of <code>&lt;something&gt;</code>.  There are so many primitives in the <code>java.util.concurrent</code> and <code>java.util.concurrent.lock</code> package. And there are also the <code>synchronized</code> keyword and <code>Object.wait()/notify()</code>. Which one fits best here?</p>