Two Laptop Bag
The moose likes Threads and Synchronization and the fly likes Thread & Http Timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread & Http Timeout" Watch "Thread & Http Timeout" New topic
Author

Thread & Http Timeout

Saad Ahmed
Greenhorn

Joined: Aug 03, 2001
Posts: 4
Hi, i'm basically trying to implement a timeout for a URL connection in an applet (can't use sockets). There is basically a time consuming function in the thread run method that opens the url stream and does a few things. The problem is if I invoke another thread to sleep for TIMEOUT in ms and then when it wakes up do an interrupt(), it really doesn't work because the interrupt can occur before the time consuming function or after...and so the thread will continue, I want the function that is time consuming/blocking to be terminated if the other thread issues an interrupt().
The problem rises from the fact that the thread run function executes some methods in a serial fashion, ie. it having no loop, while, etc...just a few statements it needs to execute, so there is no condition to check. Some people noted that in this case it would be safe to call Thread.stop() but I was wondering if there was a better solution, I thought of placing a loop before the timeconsuming function like:
while(!isInterrupted())
timeconsumefunc.retrieve()
but this only applies to one part of the thread so seems sort of wrong. Any suggestions?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Thread & Http Timeout
 
Similar Threads
Stopping a loop without stopping execution?
threads and display
Tomcat Hangs when serving bad servlet
asking about threads!!!!1
Locking, about sentence: "consuming no CPU cycles"