diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java index 7704f30c5..1eb76c285 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java @@ -104,6 +104,26 @@ public class StrolchAgent { return executor; } + /** + * Return the {@link ExecutorService} instantiated for this agent + * + * @return the {@link ExecutorService} instantiated for this agent + */ + public ExecutorService getSingleThreadExecutor() { + return getSingleThreadExecutor("Agent"); + } + + public synchronized ExecutorService getSingleThreadExecutor(String poolName) { + DBC.PRE.assertNotEmpty("poolName must be set!", poolName); + ExecutorService executor = this.executors.get(poolName); + if (executor == null) { + executor = Executors.newSingleThreadExecutor(new ThreadPoolFactory(poolName)); + this.executors.put(poolName, executor); + } + + return executor; + } + /** * Return the {@link ScheduledExecutorService} instantiated for this agent * @@ -125,8 +145,8 @@ public class StrolchAgent { } /** - * Initializes the underlying container and prepares the executor services. Before calling this method, - * {@link #setup(String, File, File, File)} must have ben called + * Initializes the underlying container and prepares the executor services. Before calling this method, {@link + * #setup(String, File, File, File)} must have ben called */ public void initialize() { if (this.container == null) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java index e285d714d..0bdc06210 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java @@ -136,6 +136,27 @@ public class StrolchComponent { return this.container.getAgent().getExecutor(poolName); } + /** + * Return the {@link ExecutorService} instantiated for this agent + * + * @return the {@link ExecutorService} instantiated for this agent + */ + protected ExecutorService getSingleThreadExecutor() { + return this.container.getAgent().getSingleThreadExecutor(); + } + + /** + * Return the {@link ExecutorService} for the given poolName instantiated for this agent + * + * @param poolName + * the name of the pool + * + * @return the {@link ExecutorService} for the given poolName instantiated for this agent + */ + protected ExecutorService getSingleThreadExecutor(String poolName) { + return this.container.getAgent().getSingleThreadExecutor(poolName); + } + /** * Return the {@link ScheduledExecutorService} instantiated for this agent *