How do I achieve event based timer?

I am trying to code an event break.

Here is a small piece of code where I am stuck.

long current_time=System.currentTimeMillis();

long end=current_time+10*1000;//a timer limit of 10 seconds

Packet_ packet_=new Packet_();


packet_ = receivePacket();//System waits for the packet to arrive on the socket in the receivePacket function.




Here, I have set the end variable with a value 10 seconds.

I want to exit the loop on either receiving the packet or the timer going off.

The problem here is, the code comes out of the while loop if the packet arrives, but it does don't come out of...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts

  • Older News
  • Blocking equivalent of Java's Timer StackOverFlow (2 days ago) - Is there a blocking equivalent of the java.util.Timer class? I'm looking for the solution which will block the thread which creates the timer.The following code is non-blocking and the "After...