glimmerveen commented on code in PR #427:
URL: https://github.com/apache/felix-dev/pull/427#discussion_r2107831833


##########
configurator/src/main/java/org/apache/felix/configurator/impl/WorkerQueue.java:
##########
@@ -18,67 +18,32 @@
  */
 package org.apache.felix.configurator.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.felix.configurator.impl.logger.SystemLogger;
 
-public class WorkerQueue implements Runnable {
-
-    private final ThreadFactory threadFactory;
-
-    private final List<Runnable> tasks = new ArrayList<>();
-
-    private volatile Thread backgroundThread;
-
-    private volatile boolean stopped = false;
+public class WorkerQueue extends ScheduledThreadPoolExecutor {
 
     public WorkerQueue() {
-        this.threadFactory = Executors.defaultThreadFactory();
-    }
-
-    public void stop() {
-        synchronized ( this.tasks ) {
-            this.stopped = true;
-        }
-    }
-
-    public void enqueue(final Runnable r) {
-        synchronized ( this.tasks ) {
-            if ( !this.stopped ) {
-                this.tasks.add(r);
-                if ( this.backgroundThread == null ) {
-                    this.backgroundThread = this.threadFactory.newThread(this);
-                    this.backgroundThread.setDaemon(true);
-                    this.backgroundThread.setName("Apache Felix Configurator 
Worker Thread");
-                    this.backgroundThread.start();
-                }
+        super(1, new ThreadFactory() {
+            @Override
+            public Thread newThread(Runnable runnable) {
+                Thread thread = new Thread(runnable);
+                thread.setDaemon(true);
+                thread.setName("Apache Felix Configurator Worker Thread");
+                return thread;
             }
-        }
+        });
+        setKeepAliveTime(5, TimeUnit.SECONDS);

Review Comment:
   This could be made configurable, but my initial proposal is to have a 
static, relatively short, keep alive time fixed in the code. Its purpose is 
mainly to let the underlying thread terminate at some point if no tasks are 
queued.



-- 
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: dev-unsubscr...@felix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to