Running Timers with Threads

Joined
Feb 2, 2008
Messages
8
Programming Experience
5-10
Hey.. I'm back again.. Thank you before i even get started to anyone who helps me with this issue..

I'm running a multithreaded program.. I have 10 threads running Sockets checking domains for uptime.. I'm trying to find out the best way to run a timer for the connection. I don't like the built in socket timeouts very much.. Seems to not timeout at the times i want.. I want to give a socket up to 1 minute to try and establish a connection with the domain.. If it suprasses 1 minute i want the thread to be halted and restarted with the next domain.

i've dabbled with the timer class, but it doesn't seem to run on it's own instance outside the thread.. if i call ConnectSocket() -- it doesn't override the thread and cut it off.. it waits until the ConnectSocket() is done.. then it allows it to work again.. Should i run timer control instances for this? Should i just use the socket timeouts.. are there any tools/tips that i'm not using.. Please help!
 
If it suprasses 1 minute i want the thread to be halted and restarted with the next domain.
[
No no no. In the Java language, the methods Thread.stop, Thread.suspend and Thread.resume are deprecated for good reason. Just because .NET allows you to abort threads does NOT mean you should do it
http://haacked.com/archive/2004/11/12/how-to-stop-a-thread.aspx

http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

You need to get out of "End Task" mentality and restructure the way youre doing your threading and networking. Setting socket timeouts is fine, catch the exceptions that connection failures and timeouts cause and move on. Understand that if a socket connection fails, it doesnt keep trying; it might fail after 1 second if the target machine refused it. If you want to retry, forge a new conenction. If the remote end picks up the socket but sends no data regardless of what you send, then the machine is alive, and you'll have to do a blocking read timeout after 60s (this is not a socket timeout or linger option) and know that the connection attempt succeeded but no data was sent..
 
Back
Top