Skip to content

Commit c118f54

Browse files
committed
+ moved pending task count increment part of async supply instead of separate blocking step
1 parent e5040f6 commit c118f54

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<groupId>io.github.q3769</groupId>
3232
<artifactId>conottle</artifactId>
33-
<version>11.0.2</version>
33+
<version>11.0.3</version>
3434
<packaging>jar</packaging>
3535
<name>conottle</name>
3636
<description>A Java concurrent API to throttle the maximum concurrency to process tasks for any given client while

src/main/java/conottle/PendingTaskCountingThrottleExecutor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.concurrent.ExecutorService;
3434
import java.util.concurrent.Executors;
3535

36-
import static coco4j.CocoUtils.supplyByUnchecked;
36+
import static coco4j.CocoUtils.callUnchecked;
3737

3838
/**
3939
* Not thread safe: Any and all non-private methods always should be externally synchronized while multithreading.
@@ -74,8 +74,10 @@ public boolean noPendingWorkAfterTaskComplete() {
7474
@Override
7575
@NonNull
7676
public <V> CompletableFuture<V> submit(Callable<V> task) {
77-
pendingTaskCount++;
78-
return CompletableFuture.supplyAsync(supplyByUnchecked(task), taskThreadPool);
77+
return CompletableFuture.supplyAsync(() -> {
78+
pendingTaskCount++;
79+
return callUnchecked(task);
80+
}, taskThreadPool);
7981
}
8082

8183
@Override

src/main/java/conottle/PooledExecutorFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
import org.apache.commons.pool2.impl.DefaultPooledObject;
3232

3333
/**
34-
* Creates pooled {@link PendingTaskCountingThrottleExecutor} instances that provide throttled async client task executions.
35-
* Each {@code PendingTaskCountingThrottleExecutor} instance throttles its client task concurrency at the max capacity of the
36-
* executor's backing thread pool.
34+
* Creates pooled {@link PendingWorkAwareExecutor} instances that provide throttled async client task executions. Each
35+
* {@code PendingWorkAwareExecutor} instance throttles its client task concurrency
3736
*/
3837
final class PooledExecutorFactory extends BasePooledObjectFactory<PendingWorkAwareExecutor> {
3938

4039
private final int maxExecutorConcurrency;
4140

4241
/**
4342
* @param maxExecutorConcurrency
44-
* max concurrent threads of the {@link PendingTaskCountingThrottleExecutor} instance produced by this factory
43+
* max concurrent tasks that can be in execution of the {@link PendingWorkAwareExecutor} instance produced
44+
* by this factory
4545
*/
4646
PooledExecutorFactory(int maxExecutorConcurrency) {
4747
this.maxExecutorConcurrency = maxExecutorConcurrency;
@@ -60,8 +60,8 @@ public PooledObject<PendingWorkAwareExecutor> wrap(PendingWorkAwareExecutor thro
6060
}
6161

6262
@Override
63-
public void destroyObject(PooledObject<PendingWorkAwareExecutor> pooledThrottlingExecutor,
64-
DestroyMode destroyMode) throws Exception {
63+
public void destroyObject(PooledObject<PendingWorkAwareExecutor> pooledThrottlingExecutor, DestroyMode destroyMode)
64+
throws Exception {
6565
try {
6666
super.destroyObject(pooledThrottlingExecutor, destroyMode);
6767
} finally {

0 commit comments

Comments
 (0)