| | |
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 |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list loop map method methods mobile netbeans newbie nextline object pong problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows





