| | |
How do I pause a thread indefinitely?
![]() |
•
•
Join Date: Feb 2008
Posts: 36
Reputation:
Solved Threads: 0
How do I pause a thread indefinitely? im creating a game and i need a thread to be paused when the user pauses the game and the thread will resume when the user unpauses the game. =) im using thread.sleep right now but it requires an integer to determine how long it will pause, but since i dont know how long the user is gonna pause the game, i think that method wont do me any good.
this might be an option
Java Syntax (Toggle Plain Text)
public static void pauze(){ while(!isContinue()){ //keep the duration small, so the game will be resumed shortly after // the user presses resume sleep(500); } } public static boolean isContinue(){ boolean returnVal = false; // this method checks in the rest of your code, whether or not your user pressed resume //returnVal = .... return returnVal; }
•
•
•
•
this might be an option
Java Syntax (Toggle Plain Text)
public static void pauze(){ while(!isContinue()){ //keep the duration small, so the game will be resumed shortly after // the user presses resume sleep(500); } } public static boolean isContinue(){ boolean returnVal = false; // this method checks in the rest of your code, whether or not your user pressed resume //returnVal = .... return returnVal; }
You may instead want to have a set method that sets the boolean expression in the loop to false so that the process can stop when it is desired for it to stop.
![]() |
Other Threads in the Java Forum
- Previous Thread: java - Could you help please..
- Next Thread: downloading image from specified url using java.
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





