org.apache.camel.spi
Interface ExecutorServiceManager

All Superinterfaces:
Service, ShutdownableService
All Known Implementing Classes:
DefaultExecutorServiceManager

public interface ExecutorServiceManager
extends ShutdownableService

Strategy to create thread pools.

This manager is pluggable so you can plugin a custom provider, for example if you want to leverage the WorkManager for a JEE server.

You may want to just implement a custom ThreadPoolFactory and rely on the DefaultExecutorServiceManager, if that is sufficient. The ThreadPoolFactory is always used for creating the actual thread pools. You can implement a custom ThreadPoolFactory to leverage the WorkManager for a JEE server.

The ThreadPoolFactory has pure JDK API, where as this ExecutorServiceManager has Camel API concepts such as ThreadPoolProfile. Therefore it may be easier to only implement a custom ThreadPoolFactory.

This manager has fine grained methods for creating various thread pools, however custom strategies do not have to exactly create those kind of pools. Feel free to return a shared or different kind of pool.

If you use the newXXX methods to create thread pools, then Camel will by default take care of shutting down those created pools when CamelContext is shutting down.

See Also:
ThreadPoolFactory

Method Summary
 ThreadPoolProfile getDefaultThreadPoolProfile()
          Gets the default thread pool profile
 String getThreadNamePattern()
          Gets the thread name patter to use
 ThreadPoolFactory getThreadPoolFactory()
          Gets the ThreadPoolFactory to use for creating the thread pools.
 ThreadPoolProfile getThreadPoolProfile(String id)
          Gets the thread pool profile by the given id
 ExecutorService newCachedThreadPool(Object source, String name)
          Creates a new cached thread pool.
 ScheduledExecutorService newDefaultScheduledThreadPool(Object source, String name)
          Creates a new scheduled thread pool using the default thread pool profile.
 ExecutorService newDefaultThreadPool(Object source, String name)
          Creates a new thread pool using the default thread pool profile.
 ExecutorService newFixedThreadPool(Object source, String name, int poolSize)
          Creates a new fixed thread pool.
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, int poolSize)
          Creates a new scheduled thread pool.
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, String profileId)
          Creates a new scheduled thread pool using a profile id
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, ThreadPoolProfile profile)
          Creates a new scheduled thread pool using a profile
 ExecutorService newSingleThreadExecutor(Object source, String name)
          Creates a new single-threaded thread pool.
 ScheduledExecutorService newSingleThreadScheduledExecutor(Object source, String name)
          Creates a new single-threaded thread pool.
 ExecutorService newThreadPool(Object source, String name, int poolSize, int maxPoolSize)
          Creates a new thread pool.
 ExecutorService newThreadPool(Object source, String name, String profileId)
          Creates a new thread pool using using the given profile id
 ExecutorService newThreadPool(Object source, String name, ThreadPoolProfile profile)
          Creates a new thread pool using the given profile
 void registerThreadPoolProfile(ThreadPoolProfile profile)
          Registers the given thread pool profile
 String resolveThreadName(String name)
          Creates a full thread name
 void setDefaultThreadPoolProfile(ThreadPoolProfile defaultThreadPoolProfile)
          Sets the default thread pool profile
 void setThreadNamePattern(String pattern)
          Sets the thread name pattern used for creating the full thread name.
 void setThreadPoolFactory(ThreadPoolFactory threadPoolFactory)
          Sets a custom ThreadPoolFactory to use
 void shutdown(ExecutorService executorService)
          Shutdown the given executor service.
 List<Runnable> shutdownNow(ExecutorService executorService)
          Shutdown now the given executor service.
 
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Method Detail

getThreadPoolFactory

ThreadPoolFactory getThreadPoolFactory()
Gets the ThreadPoolFactory to use for creating the thread pools.

Returns:
the thread pool factory

setThreadPoolFactory

void setThreadPoolFactory(ThreadPoolFactory threadPoolFactory)
Sets a custom ThreadPoolFactory to use

Parameters:
threadPoolFactory - the thread pool factory

resolveThreadName

String resolveThreadName(String name)
Creates a full thread name

Parameters:
name - name which is appended to the full thread name
Returns:
the full thread name

getThreadPoolProfile

ThreadPoolProfile getThreadPoolProfile(String id)
Gets the thread pool profile by the given id

Parameters:
id - id of the thread pool profile to get
Returns:
the found profile, or null if not found

registerThreadPoolProfile

void registerThreadPoolProfile(ThreadPoolProfile profile)
Registers the given thread pool profile

Parameters:
profile - the profile

setDefaultThreadPoolProfile

void setDefaultThreadPoolProfile(ThreadPoolProfile defaultThreadPoolProfile)
Sets the default thread pool profile

Parameters:
defaultThreadPoolProfile - the new default thread pool profile

getDefaultThreadPoolProfile

ThreadPoolProfile getDefaultThreadPoolProfile()
Gets the default thread pool profile

Returns:
the default profile which are newer null

setThreadNamePattern

void setThreadNamePattern(String pattern)
                          throws IllegalArgumentException
Sets the thread name pattern used for creating the full thread name.

The default pattern is: Camel (#camelId#) thread ##counter# - #name#

Where #camelId# is the name of the CamelContext
and #counter# is a unique incrementing counter.
and #name# is the regular thread name.
You can also use #longName# is the long thread name which can includes endpoint parameters etc.

Parameters:
pattern - the pattern
Throws:
IllegalArgumentException - if the pattern is invalid.

getThreadNamePattern

String getThreadNamePattern()
Gets the thread name patter to use

Returns:
the pattern

newDefaultThreadPool

ExecutorService newDefaultThreadPool(Object source,
                                     String name)
Creates a new thread pool using the default thread pool profile.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newDefaultScheduledThreadPool

ScheduledExecutorService newDefaultScheduledThreadPool(Object source,
                                                       String name)
Creates a new scheduled thread pool using the default thread pool profile.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newThreadPool

ExecutorService newThreadPool(Object source,
                              String name,
                              ThreadPoolProfile profile)
Creates a new thread pool using the given profile

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profile - the profile with the thread pool settings to use
Returns:
the created thread pool

newThreadPool

ExecutorService newThreadPool(Object source,
                              String name,
                              String profileId)
Creates a new thread pool using using the given profile id

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profileId - the id of the profile with the thread pool settings to use
Returns:
the created thread pool, or null if the thread pool profile could not be found

newThreadPool

ExecutorService newThreadPool(Object source,
                              String name,
                              int poolSize,
                              int maxPoolSize)
Creates a new thread pool.

Will fallback and use values from the default thread pool profile for keep alive time, rejection policy and other parameters which cannot be specified.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
poolSize - the core pool size
maxPoolSize - the maximum pool size
Returns:
the created thread pool

newSingleThreadExecutor

ExecutorService newSingleThreadExecutor(Object source,
                                        String name)
Creates a new single-threaded thread pool. This is often used for background threads.

Notice that there will always be a single thread in the pool. If you want the pool to be able to shrink to no threads, then use the newThreadPool method, and use 0 in core pool size, and 1 in max pool size.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newCachedThreadPool

ExecutorService newCachedThreadPool(Object source,
                                    String name)
Creates a new cached thread pool.

Important: Using cached thread pool is discouraged as they have no upper bound and can overload the JVM.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newFixedThreadPool

ExecutorService newFixedThreadPool(Object source,
                                   String name,
                                   int poolSize)
Creates a new fixed thread pool.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
poolSize - the core pool size
Returns:
the created thread pool

newScheduledThreadPool

ScheduledExecutorService newScheduledThreadPool(Object source,
                                                String name,
                                                int poolSize)
Creates a new scheduled thread pool.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
poolSize - the core pool size
Returns:
the created thread pool

newSingleThreadScheduledExecutor

ScheduledExecutorService newSingleThreadScheduledExecutor(Object source,
                                                          String name)
Creates a new single-threaded thread pool. This is often used for background threads.

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newScheduledThreadPool

ScheduledExecutorService newScheduledThreadPool(Object source,
                                                String name,
                                                ThreadPoolProfile profile)
Creates a new scheduled thread pool using a profile

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profile - the profile with the thread pool settings to use
Returns:
created thread pool

newScheduledThreadPool

ScheduledExecutorService newScheduledThreadPool(Object source,
                                                String name,
                                                String profileId)
Creates a new scheduled thread pool using a profile id

Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profileId - the id of the profile with the thread pool settings to use
Returns:
created thread pool

shutdown

void shutdown(ExecutorService executorService)
Shutdown the given executor service.

Parameters:
executorService - the executor service to shutdown
See Also:
ExecutorService.shutdown()

shutdownNow

List<Runnable> shutdownNow(ExecutorService executorService)
Shutdown now the given executor service.

Parameters:
executorService - the executor service to shutdown now
Returns:
list of tasks that never commenced execution
See Also:
ExecutorService.shutdownNow()


Apache CAMEL