• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time Interval for a Thread

 
Gangadhara Rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have requirement of late response handling . I have to write a piece of code which calls the webservice, and if the webservice returns the response in a required amount of time, then I will take the response, if it exceeds the time I have specified then my code should terminate the requesting process and I will have to display some error message.

Can I use a thread for handling this, if so how do I specify the time interval for it.

Plese suggest me as to how it can be handled.

Thanks in advance.
Gangadhar
 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using threads is simple,

call the webservice code in seperate thread in a new run method....your main code wil still keep running...(Main thread)..


Might be your question is somethin different.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To follow up on that, your "main" thread can start another thread to do the remote call, and join() that thread with a timeout parameter.

In Java5 or later, look into Future and FutureTask which do roughly the same thing in clearer code.
 
Gangadhara Rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for giving replies.
I am giving a try with your given suggestions.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gangadhara Rao:
I am giving a try with your given suggestions.


Let us know how it works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!