summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/src/main/java/org/openslx/taskmanager/main/Taskmanager.java24
1 files changed, 6 insertions, 18 deletions
diff --git a/daemon/src/main/java/org/openslx/taskmanager/main/Taskmanager.java b/daemon/src/main/java/org/openslx/taskmanager/main/Taskmanager.java
index f9b7752..1325dca 100644
--- a/daemon/src/main/java/org/openslx/taskmanager/main/Taskmanager.java
+++ b/daemon/src/main/java/org/openslx/taskmanager/main/Taskmanager.java
@@ -5,11 +5,9 @@ import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import org.apache.log4j.Logger;
import org.openslx.taskmanager.Global;
@@ -46,8 +44,7 @@ public class Taskmanager implements FinishCallback, Runnable
*/
private final Map<String, AbstractTask> instances = new ConcurrentHashMap<>();
- private final Lock workLock = new ReentrantLock();
- private final Condition doCheckForWork = workLock.newCondition();
+ private final Semaphore doCheckForWork = new Semaphore( 0 );
/*
* Static methods
@@ -142,12 +139,7 @@ public class Taskmanager implements FinishCallback, Runnable
*/
protected void checkForWork()
{
- workLock.lock();
- try {
- doCheckForWork.signalAll();
- } finally {
- workLock.unlock();
- }
+ doCheckForWork.release();
}
@Override
@@ -161,12 +153,8 @@ public class Taskmanager implements FinishCallback, Runnable
{
try {
while ( !Global.doShutdown ) {
- workLock.lock();
- try {
- doCheckForWork.await( 1, TimeUnit.MINUTES );
- } finally {
- workLock.unlock();
- }
+ doCheckForWork.tryAcquire( 1, TimeUnit.MINUTES );
+ doCheckForWork.drainPermits();
try {
for ( Iterator<AbstractTask> it = instances.values().iterator(); it.hasNext(); ) {
AbstractTask task = it.next();
@@ -176,8 +164,8 @@ public class Taskmanager implements FinishCallback, Runnable
continue;
}
if ( task.canStart() ) {
- threadPool.execute( task );
log.debug( "Started Task " + task.getClass().getSimpleName() + " (" + task.getId() + ")" );
+ threadPool.execute( task );
}
}
} catch ( RejectedExecutionException e ) {