Class AdvancedThreadPoolService
- java.lang.Object
-
- jadex.bridge.service.BasicService
-
- jadex.platform.service.threadpool.AdvancedThreadPoolService
-
- All Implemented Interfaces:
IInternalService
,IService
,IDaemonThreadPoolService
,IThreadPoolService
,IThreadPool
public class AdvancedThreadPoolService extends BasicService implements IThreadPoolService, IDaemonThreadPoolService
A thread pool based on the java.util.concurrent package.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ExecutorService
executor
The executor service.protected static MonitoredThreadPoolExecutor
GLOBAL_EXECUTOR
The global executor.protected java.util.List<IChangeListener<java.lang.Void>>
listeners
The finished listeners.protected Future<java.lang.Void>
shutdown
Future for pool shutdown.-
Fields inherited from class jadex.bridge.service.BasicService
idcnt, impltype, internalaccess, providerid, shutdowned, sid, started, type
-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description AdvancedThreadPoolService(IComponentIdentifier provider, boolean daemon)
Create a new ThreadPool.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFinishListener(IChangeListener<java.lang.Void> listener)
Add a finish listener;void
dispose()
Shutdown the thread pool.void
execute(java.lang.Runnable task)
Execute a task in its own thread.void
executeForever(java.lang.Runnable task)
Execute a task in its own thread.boolean
isRunning()
Test if the thread pool is running.static void
main(java.lang.String[] args)
Test main.protected void
notifyFinishListeners()
Notify the finish listeners.IFuture<java.lang.Void>
shutdown()
Service shutdown.-
Methods inherited from class jadex.bridge.service.BasicService
createServiceIdentifier, createServiceIdentifier, equals, generateServiceName, getInterfaceType, getInternalAccess, getInvokeMethod, getMethodInfos, getMethodTimeout, getPropertyMap, getProviderId, getServiceId, hashCode, initNFProperties, invokeMethod, isValid, setComponentAccess, setPropertyMap, setServiceIdentifier, shutdownService, startService, toString
-
-
-
-
Field Detail
-
GLOBAL_EXECUTOR
protected static volatile MonitoredThreadPoolExecutor GLOBAL_EXECUTOR
The global executor.
-
executor
protected java.util.concurrent.ExecutorService executor
The executor service.
-
listeners
protected java.util.List<IChangeListener<java.lang.Void>> listeners
The finished listeners.
-
shutdown
protected Future<java.lang.Void> shutdown
Future for pool shutdown.
-
-
Constructor Detail
-
AdvancedThreadPoolService
public AdvancedThreadPoolService(IComponentIdentifier provider, boolean daemon)
Create a new ThreadPool.
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable task)
Execute a task in its own thread.- Specified by:
execute
in interfaceIThreadPool
- Parameters:
task
- The task to execute.
-
executeForever
public void executeForever(java.lang.Runnable task)
Execute a task in its own thread. The pool expects the thread executing the task to never return. Preferably use this method if you want to permanently retrieve a thread e.g. for repeated blocking operations.- Specified by:
executeForever
in interfaceIThreadPool
- Parameters:
task
- The task to execute.
-
shutdown
public IFuture<java.lang.Void> shutdown()
Service shutdown.- Returns:
- Null, when done.
-
dispose
public void dispose()
Shutdown the thread pool.- Specified by:
dispose
in interfaceIThreadPool
-
isRunning
public boolean isRunning()
Test if the thread pool is running.- Specified by:
isRunning
in interfaceIThreadPool
-
addFinishListener
public void addFinishListener(IChangeListener<java.lang.Void> listener)
Add a finish listener;- Specified by:
addFinishListener
in interfaceIThreadPool
-
notifyFinishListeners
protected void notifyFinishListeners()
Notify the finish listeners.
-
main
public static void main(java.lang.String[] args)
Test main.
-
-