title: Best way to synchronize asynchronous task
body: <p>My Problem: I've got 802.15.4 Wireless network connected to a serial port (using a wrapper).
  I can send packages into the network and listen for incoming packages.
  As you can imagine this is highly asynchronous. </p>
  
  <p>Here comes the task: I want to send commands to the network and wait for the response in one function call. For Example: I want to get the temperature from the Node with the network ID 1338.</p>
  
  <pre><code>double getTemperature(int id) throws Exception { .... }
  </code></pre>
  
  <p>Is there a better way of waiting for a response message other than doing all this "synchonized(object) wait(..) notify(..)" stuff?</p>
  
  <p>Best regards,
  bigbohne</p>
  
  <p>Maybe to add some spice:</p>
  
  <p>This should all end in a webinterface where user can request these commands (either through ajax or directly). I've also thought of caching responce values in a database. 
  But for some commands you MUSS have a direct answer of success/failure</p>