• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling timeout using thread  RSS feed

 
aleah de guzman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my application is connecting to another application but that application doesnt have a connection timeout. So i want to handle the connection timeout in my side. For example, my application will try to connect to the other within 15 seconds. If no response yet, an exception will be thrown. How can i achieve this using threads? Can't seem to find suitable example in the net. Thanks in advance.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not in 25 words or less.

What is your application? How is this "connection" done? Look up wait()/notify() or Condition await()/signal().
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use jdk 5? if yes, have a look at Future, that may serve your purpose.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just posted this elsewhere so it's fresh in memory. Future is cleaner, this was in 1.3:

This shows no attempt to stop the thread if it runs too long. It will always run to completion even if we're not waiting for it any more. You might know enough about your RealWork class to decide interrupting it is worth while.

Is that close?
 
arulk pillai
Author
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!