| | |
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 |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linked linux list loan machine map method methods migrate mobile netbeans objects oriented output phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows





