Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2003

Tip: Looking for answers? Try searching our database.

how can I stop a thread from sleeping?

Thread view: 
mimisam - 31 Oct 2003 10:16 GMT
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) {}
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.