diff options
Diffstat (limited to 'src/org/apg/PausableThread.java')
-rw-r--r-- | src/org/apg/PausableThread.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/org/apg/PausableThread.java b/src/org/apg/PausableThread.java new file mode 100644 index 000000000..87258d36c --- /dev/null +++ b/src/org/apg/PausableThread.java @@ -0,0 +1,35 @@ +package org.apg; + +public class PausableThread extends Thread { + private boolean mPaused = false; + + public PausableThread(Runnable runnable) { + super(runnable); + } + + public void pause() { + synchronized (this) { + mPaused = true; + while (mPaused) { + try { + wait(); + } catch (InterruptedException e) { + // ignore + } + } + } + } + + public void unpause() { + synchronized (this) { + mPaused = false; + notify(); + } + } + + public boolean isPaused() { + synchronized (this) { + return mPaused; + } + } +} |