diff options
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java')
-rw-r--r-- | OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java index aa21581c6..377a8d5d6 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/PausableThreadPoolExecutor.java @@ -17,11 +17,7 @@ package org.sufficientlysecure.keychain.util; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; @@ -32,59 +28,63 @@ import java.util.concurrent.locks.ReentrantLock; public class PausableThreadPoolExecutor extends ThreadPoolExecutor { public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, - TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) { + TimeUnit unit, BlockingQueue<Runnable> workQueue, + RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); } public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, - TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, - RejectedExecutionHandler handler) { + TimeUnit unit, BlockingQueue<Runnable> workQueue, + ThreadFactory threadFactory, + RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); } public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, - TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) { + TimeUnit unit, BlockingQueue<Runnable> workQueue, + ThreadFactory threadFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); } public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, - TimeUnit unit, BlockingQueue<Runnable> workQueue) { + TimeUnit unit, BlockingQueue<Runnable> workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } - private boolean isPaused; - private ReentrantLock pauseLock = new ReentrantLock(); - private Condition unpaused = pauseLock.newCondition(); + private boolean mIsPaused; + private ReentrantLock mPauseLock = new ReentrantLock(); + private Condition mUnPaused = mPauseLock.newCondition(); protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); - pauseLock.lock(); + mPauseLock.lock(); try { - while (isPaused) - unpaused.await(); + while (mIsPaused) { + mUnPaused.await(); + } } catch (InterruptedException ie) { t.interrupt(); } finally { - pauseLock.unlock(); + mPauseLock.unlock(); } } public void pause() { - pauseLock.lock(); + mPauseLock.lock(); try { - isPaused = true; + mIsPaused = true; } finally { - pauseLock.unlock(); + mPauseLock.unlock(); } } public void resume() { - pauseLock.lock(); + mPauseLock.lock(); try { - isPaused = false; - unpaused.signalAll(); + mIsPaused = false; + mUnPaused.signalAll(); } finally { - pauseLock.unlock(); + mPauseLock.unlock(); } } -}
\ No newline at end of file +} |