2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-05-01 11:08:11 -07:00

Workflow work waiting tweaks.

This commit is contained in:
Geert Bevin 2023-01-20 09:47:40 -05:00
parent 9d04473685
commit 2e127ddd93

View file

@ -58,7 +58,17 @@ public class Workflow {
} }
/** /**
* Creates a new workflow instance with a provided executor. * Creates a new workflow instance with a provided parent properties.
*
* @param properties the parent hierarchical properties
* @since 1.0
*/
public Workflow(HierarchicalProperties properties) {
this(Executors.newCachedThreadPool(), properties);
}
/**
* Creates a new workflow instance.
* *
* @param executor the executor to use for running the work * @param executor the executor to use for running the work
* @param properties the parent hierarchical properties * @param properties the parent hierarchical properties
@ -103,12 +113,12 @@ public class Workflow {
* @since 1.0 * @since 1.0
*/ */
public void start(final Class<? extends Work> klass) { public void start(final Class<? extends Work> klass) {
activeWorkCount_.increment();
workExecutor_.submit(() -> { workExecutor_.submit(() -> {
try { try {
activeWorkCount_.increment();
runner_.start(klass); runner_.start(klass);
activeWorkCount_.decrement();
activeWorkCount_.decrement();
signalWhenAllWorkFinished(); signalWhenAllWorkFinished();
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -123,12 +133,12 @@ public class Workflow {
* @since 1.0 * @since 1.0
*/ */
public void start(Work work) { public void start(Work work) {
activeWorkCount_.increment();
workExecutor_.submit(() -> { workExecutor_.submit(() -> {
try { try {
activeWorkCount_.increment();
runner_.start(work); runner_.start(work);
activeWorkCount_.decrement();
activeWorkCount_.decrement();
signalWhenAllWorkFinished(); signalWhenAllWorkFinished();
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -286,12 +296,12 @@ public class Workflow {
*/ */
public void waitForPausedWork() public void waitForPausedWork()
throws InterruptedException { throws InterruptedException {
if (!eventsMapping_.isEmpty()) {
return;
}
workLock_.lock(); workLock_.lock();
try { try {
if (!eventsMapping_.isEmpty()) {
return;
}
workPaused_.await(); workPaused_.await();
} finally { } finally {
workLock_.unlock(); workLock_.unlock();
@ -306,12 +316,12 @@ public class Workflow {
*/ */
public void waitForNoWork() public void waitForNoWork()
throws InterruptedException { throws InterruptedException {
if (activeWorkCount_.sum() == 0) {
return;
}
workLock_.lock(); workLock_.lock();
try { try {
if (activeWorkCount_.sum() == 0) {
return;
}
workFinished_.await(); workFinished_.await();
} finally { } finally {
workLock_.unlock(); workLock_.unlock();