in my code I'm using
Thread.currentThread().sleep(sleepTime);
in the main (non Thread object) portion of the code.
It appears to be working fine, but I'm worried that there might be some hidden pitfall that will bite me in the ass later.
Is there a better way to make your main process sit around for a while? or is this the prescribed methodology?
EDIT:
In answer to why I'm doing it this way...
I have a process that connects via HTTP or FTP to remote hosts and does stuff.
In other words...
stuff...
connect to remote...
do stuff with remote connection...
close connection...
more stuff...
repeat as necessary.
I've found that in very very rare instances, the connection just goes off into la la land. It doesn't fail, it doesn't throw any exception, it just goes away. And it's blocking, so there's no in-line way to set a timer.
So, my solution is to do this...
stuff...
start new thread with connection in it...
go into an infinite loop with a timer in the MAIN process (not in the spawned thread) and wait for either
a) the connection thread to complete its task and set some flag to "done"
or
b) wait some preset amount of time and if the connection thread has not reported that it's finished, kill it and move on.
It is in the main process that I intend to sleep for some time, wake up, and see if the MAX_WAIT_TIME has expired. If not, go back to sleep and wait some more.
It seems much more efficient (on the processor) than sitting in standard while loop, since that would really interfere with the connection thread's business of doing what it needs to do.
I guess my question really is... is there anything unsafe about this approach. I see from the answers that, given what I'm doing, it looks like there isn't. Perhaps I should have asked if there is a more standardized approach?