Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread & Http Timeout

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic