Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to provide timeout for a java thread - Very Very urgent

807603Nov 20 2007 — edited Nov 20 2007
Dear java gurus,

We use a java application, the run method of a class invokes a thread javaProcess as shown below.

public void run()
{
try
{
ServerSocket server = new ServerSocket(inPort);
Socket client = null;
int i=0;
while (true)
{
client = server.accept();
new javaProcess(client);
i++;
//ends here
}
}catch (NumberFormatException numberformatexceptionObj)
{
logger.writeError(" IOException :" + numberformatexceptionObj);
}
catch (InterruptedIOException interruptedioexceptionObj)
{
logger.writeError(" IOException :" + interruptedioexceptionObj);
}
catch (IOException ioexceptionObj)
{
logger.writeError(" IOException :" + ioexceptionObj);
}


}

The following code is the one invoked by the previous run() method. The run() method of the javaProcess carries some activity. We need to put a timeout on this. i.e irrespective of the status of the activitiy, this thread should be killed. Hope i am clear. Please get back if i am not clear. The javaProcess should be given a timeout. Please tell us how can this be done...

public javaProcess(Socket _client)
{
this.client = _client;
this.start();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2007
Added on Nov 20 2007
9 comments
553 views