stefan-egli commented on code in PR #6:
URL:
https://github.com/apache/sling-org-apache-sling-commons-scheduler/pull/6#discussion_r1867565797
##########
src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java:
##########
@@ -67,8 +72,23 @@ public void setInstanceName(final String name) {
*/
@Override
public boolean runInThread(final Runnable job) {
- this.executor.execute(job);
-
+ synchronized ( this.lock ) {
+ if ( this.counter == 0 ) {
Review Comment:
what about a paranoia check like so?
```
if ( this.counter <= 0 ) {
```
##########
src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java:
##########
@@ -77,14 +97,28 @@ public boolean runInThread(final Runnable job) {
*/
@Override
public int blockForAvailableThreads() {
- return this.executor.getConfiguration().getMaxPoolSize() -
this.executor.getConfiguration().getQueueSize();
+ synchronized ( this.lock ) {
+ while ( this.counter == 0 ) {
+ try {
+ this.lock.wait();
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
Review Comment:
another paranoia idea :
```
while ( this.counter <= 0 ) {
try {
this.lock.wait(1000);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
```
##########
src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java:
##########
@@ -67,8 +72,23 @@ public void setInstanceName(final String name) {
*/
@Override
public boolean runInThread(final Runnable job) {
- this.executor.execute(job);
-
+ synchronized ( this.lock ) {
+ if ( this.counter == 0 ) {
+ return false;
+ }
+ this.counter--;
+ }
+ final Runnable r = () -> {
+ try {
+ job.run();
+ } finally {
+ synchronized ( this.lock ) {
+ this.counter++;
+ this.lock.notify();
+ }
+ }
+ };
+ this.executor.execute(r);
Review Comment:
could go more paranoia by checking for Error or RuntimeException here (and
then inc the counter as well) ...
##########
src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java:
##########
@@ -21,13 +21,18 @@
public class QuartzThreadPool implements org.quartz.spi.ThreadPool {
/** Our executor thread pool */
- private ThreadPool executor;
+ private volatile ThreadPool executor;
+
+ private final Object lock = new Object();
+
+ private volatile int counter;
/**
* Create a new wrapper implementation for Quartz.
*/
public QuartzThreadPool(final ThreadPool executor) {
this.executor = executor;
+ this.counter = executor.getConfiguration().getMaxPoolSize();
Review Comment:
can `maxPoolSize` ever be zero or negative?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]