title: How do I signal a sleeping thread in Java?
body: <p>I'm writing a UDP client-server pair for a networks class, and I have hit on a problem. This is a rather unorthodox networks assignment, so a little background first: </p>
  
  <p>The goal is to create a server to implement push-based notifications. The key point here is that the <em>server</em> has to contact the <em>client</em> at whatever address it was last seen, as well listen for the client's control packets. So therefore, I have a thread running on the client periodically sending out UDP packets to the server, which logs their origin for when it needs to send out a response. This technique also busts through NAT's, as the send refreshes the address translation. </p>
  
  <p>So then, here is my dilemma: Unless I'm mistaken, the NAT maps its own address and a generated port number onto it's clients address <em>port</em> combination. Therefore, in order to successfully traverse the NAT, I need to move all my packets through one port on the client machine. The updater thread would simply have to listen for a time, push out an update packet, and go back to listening. </p>
  
  <p>Then here is where it get hairy. If the original thread, which wants to perform some action, wants the port, it has to wake the announcer, which is blocking while waiting for the response. </p>
  
  <p>How can I pull this off in Java? </p>
  
  <p>P.S.: If it turns out that the NAT would allow a communication on a different port to go through, then things are awesome. </p>