aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/thialfihar/android/apg/PausableThread.java
blob: 8a68c8a28b2841208e928b0a7b717ba16c631b3d (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.thialfihar.android.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;
        }
    }
}