hi,
I have a program(like the following codes) which needs to sleep for 20
seconds. How can i make it stop sleeping if i want it to be alive
before 20 seconds is up?(e.g. when a cancel button is clicked).
Any help will be appreciated !!
Thanks.
public static void a()
{
delay(20000);
}
public static void delay(int d)
{
try {
Thread.sleep(d);
} catch (InterruptedException e) {}
}
Christophe Vanfleteren - 31 Oct 2003 10:21 GMT
> hi,
>
[quoted text clipped - 15 lines]
> } catch (InterruptedException e) {}
> }
You might want to check the answer you got in c.l.j.help instead of posting
here again 3 minutes later.

Signature
Regards,
Christophe Vanfleteren
Andrew Thompson - 31 Oct 2003 10:40 GMT
> > I have a program(like the following codes) which needs to sleep for 20
...
> You might want to check the answer you got in c.l.j.help instead of posting
> here again 3 minutes later.
This is referred to as multi-posting.
You might benefit from checking Jon Skeet's
article on 'How to ask questions on Newsgroups'
http://jinx.swiki.net/79
Lots of great tips ..including some I should pay more
attention to myself!
--
Andrew Thompson
http://www.AThompson.info/
http://www.PhySci.org/
http://www.1point1C.org/
Òscar Pérez del Campo - 31 Oct 2003 12:40 GMT
Hi,
the method Thread.interrupt() does exactly what you want. In your cancel
button you should call "threadToInterrupt.interrupt()" over the thread
object you want to resume.
Remember to catch the InterruptedException on your "delay" method (if
needed).
Òscar
> hi,
>
[quoted text clipped - 15 lines]
> } catch (InterruptedException e) {}
> }