open-keychain/src/org/thialfihar/android/apg/PausableThread.java

36 lines
725 B
Java
Raw Normal View History

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;
}
}
}