aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apg/PausableThread.java
blob: 87258d36cf9db04f960f0e8bb40ae23fd95a96df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
        }
    }
}