Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final Object LOCK = new Object();
- private boolean pauseThreadFlag = false;
- private void checkForPause() throws InterruptedException
- {
- if(pauseThreadFlag)
- {
- if(this.getState().equals(Thread.State.RUNNABLE))
- {
- synchronized(LOCK)
- {
- LOCK.wait();
- pauseThreadFlag = false;
- }
- }
- }
- }
- public void pauseThread()
- {
- pauseThreadFlag = true;
- }
- public void resumeThread()
- {
- if(this.getState().equals(Thread.State.WAITING))
- {
- synchronized(LOCK)
- {
- LOCK.notify();
- pauseThreadFlag = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement