Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread & Http Timeout

Saad Ahmed
Posts: 4
  • Mark post as helpful
  • send pies
  • 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:
but this only applies to one part of the thread so seems sort of wrong. Any suggestions?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic