This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/turbine-core.git

commit d7362665faa34ffc170fe2c9d50e9ea51330d8fc
Author: Thomas Vandahl <[email protected]>
AuthorDate: Wed Jan 7 18:25:47 2026 +0100

    Move WorkerThread into private Lambda function
---
 .../schedule/AbstractSchedulerService.java         |  50 +++++++++-
 .../turbine/services/schedule/WorkerThread.java    | 102 ---------------------
 2 files changed, 49 insertions(+), 103 deletions(-)

diff --git 
a/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java 
b/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
index 783d04b2..fa5655c4 100644
--- 
a/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
+++ 
b/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.apache.turbine.modules.ScheduledJobLoader;
 import org.apache.turbine.services.InitializationException;
 import org.apache.turbine.services.TurbineBaseService;
 import org.apache.turbine.util.TurbineException;
@@ -343,7 +344,7 @@ public abstract class AbstractSchedulerService extends 
TurbineBaseService implem
                     taskName = je.getTask();
 
                     // Get a thread to run the job.
-                    threadPool.execute(new WorkerThread(je));
+                    threadPool.execute(() -> runJob(je));
                 }
                 else
                 {
@@ -361,4 +362,51 @@ public abstract class AbstractSchedulerService extends 
TurbineBaseService implem
             clearThread();
         }
     }
+
+    /**
+     * Run the job.
+     *
+     * @param je the job descriptor
+     */
+    private void runJob(JobEntry je)
+    {
+        if (je == null || je.isActive())
+        {
+            return;
+        }
+
+        try
+        {
+            if (!je.isActive())
+            {
+                je.setActive(true);
+                logStateChange(je, "started");
+                ScheduledJobLoader.getInstance().exec(je, je.getTask());
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("Error in WorkerThread for scheduled job #{}, task: {}",
+                    Integer.valueOf(je.getJobId()), je.getTask(), e);
+        }
+        finally
+        {
+            if (je.isActive())
+            {
+                je.setActive(false);
+                logStateChange(je, "completed");
+            }
+        }
+    }
+
+    /**
+     * Macro to log <code>JobEntry</code> status information.
+     *
+     * @param state The new state of the <code>JobEntry</code>.
+     */
+    private final void logStateChange(JobEntry je, String state)
+    {
+        log.error("Scheduled job #{} {}, task: {}",
+                Integer.valueOf(je.getJobId()), state, je.getTask());
+    }
 }
diff --git a/src/java/org/apache/turbine/services/schedule/WorkerThread.java 
b/src/java/org/apache/turbine/services/schedule/WorkerThread.java
deleted file mode 100644
index 8b90d952..00000000
--- a/src/java/org/apache/turbine/services/schedule/WorkerThread.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.apache.turbine.services.schedule;
-
-import org.apache.logging.log4j.LogManager;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.logging.log4j.Logger;
-import org.apache.turbine.modules.ScheduledJobLoader;
-
-/**
- * Wrapper for a <code>JobEntry</code> to actually perform the job's action.
- *
- * @author <a href="mailto:[email protected]";>Dave Bryson</a>
- * @author <a href="mailto:[email protected]";>Daniel Rall</a>
- * @author <a href="mailto:[email protected]";>Henning P. Schmiedehausen</a>
- * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
- * @version $Id: WorkerThread.java 534527 2007-05-02 16:10:59Z tv $
- */
-public class WorkerThread
-        implements Runnable
-{
-    /**
-     * The <code>JobEntry</code> to run.
-     */
-    private JobEntry je = null;
-
-    /** Logging */
-    private static final Logger log = 
LogManager.getLogger(ScheduleService.LOGGER_NAME);
-
-    /**
-     * Creates a new worker to run the specified <code>JobEntry</code>.
-     *
-     * @param je The <code>JobEntry</code> to create a worker for.
-     */
-    public WorkerThread(JobEntry je)
-    {
-        this.je = je;
-    }
-
-    /**
-     * Run the job.
-     */
-    @Override
-    public void run()
-    {
-        if (je == null || je.isActive())
-        {
-            return;
-        }
-
-        try
-        {
-            if (!je.isActive())
-            {
-                je.setActive(true);
-                logStateChange("started");
-                ScheduledJobLoader.getInstance().exec(je, je.getTask());
-            }
-        }
-        catch (Exception e)
-        {
-            log.error("Error in WorkerThread for scheduled job #{}, task: {}",
-                    Integer.valueOf(je.getJobId()), je.getTask(), e);
-        }
-        finally
-        {
-            if (je.isActive())
-            {
-                je.setActive(false);
-                logStateChange("completed");
-            }
-        }
-    }
-
-    /**
-     * Macro to log <code>JobEntry</code> status information.
-     *
-     * @param state The new state of the <code>JobEntry</code>.
-     */
-    private final void logStateChange(String state)
-    {
-        log.error("Scheduled job #{} {}, task: {}",
-                Integer.valueOf(je.getJobId()), state, je.getTask());
-    }
-}

Reply via email to