Class ThreadPoolProviderImpl
- java.lang.Object
-
- org.hibernate.search.engine.environment.thread.impl.ThreadPoolProviderImpl
-
- All Implemented Interfaces:
ThreadPoolProvider
public class ThreadPoolProviderImpl extends Object implements ThreadPoolProvider
Helper to create threads and executors.- Author:
- Sanne Grinovero
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classThreadPoolProviderImpl.BlockPolicyA handler for rejected tasks that will have the caller block until space is available.
-
Constructor Summary
Constructors Constructor Description ThreadPoolProviderImpl(BeanHolder<? extends ThreadProvider> threadProviderHolder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanisScheduledExecutorBlocking()ThreadPoolExecutornewFixedThreadPool(int threads, String threadNamePrefix)Creates a new fixed sizeThreadPoolExecutor.ThreadPoolExecutornewFixedThreadPool(int threads, String threadNamePrefix, int queueSize)Creates a new fixed sizeThreadPoolExecutor.ScheduledExecutorServicenewScheduledExecutor(int threads, String threadNamePrefix)Creates a new fixed sizeScheduledExecutorService.ThreadProviderthreadProvider()
-
-
-
Constructor Detail
-
ThreadPoolProviderImpl
public ThreadPoolProviderImpl(BeanHolder<? extends ThreadProvider> threadProviderHolder)
-
-
Method Detail
-
close
public void close()
-
threadProvider
public ThreadProvider threadProvider()
- Specified by:
threadProviderin interfaceThreadPoolProvider- Returns:
- The underlying thread provider.
-
newFixedThreadPool
public ThreadPoolExecutor newFixedThreadPool(int threads, String threadNamePrefix)
Description copied from interface:ThreadPoolProviderCreates a new fixed sizeThreadPoolExecutor.It's using a blocking queue of maximum 1000 elements and the rejection policy is set to block until the queue can accept the task. These settings are required to cap the queue, to make sure the timeouts are reasonable for most jobs.
- Specified by:
newFixedThreadPoolin interfaceThreadPoolProvider- Parameters:
threads- the number of threadsthreadNamePrefix- a label to identify the threads; useful for profiling.- Returns:
- the new ExecutorService
-
newFixedThreadPool
public ThreadPoolExecutor newFixedThreadPool(int threads, String threadNamePrefix, int queueSize)
Description copied from interface:ThreadPoolProviderCreates a new fixed sizeThreadPoolExecutor.It's using a blocking queue of maximum
queueSizeelements and the rejection policy is set to block until the queue can accept the task. These settings are required to cap the queue, to make sure the timeouts are reasonable for most jobs.- Specified by:
newFixedThreadPoolin interfaceThreadPoolProvider- Parameters:
threads- the number of threadsthreadNamePrefix- a label to identify the threads; useful for profiling.queueSize- the size of the queue to store Runnables when all threads are busy- Returns:
- the new ExecutorService
-
newScheduledExecutor
public ScheduledExecutorService newScheduledExecutor(int threads, String threadNamePrefix)
Description copied from interface:ThreadPoolProviderCreates a new fixed sizeScheduledExecutorService.The queue size is not capped, so users should take care of checking they submit a reasonable amount of tasks.
- Specified by:
newScheduledExecutorin interfaceThreadPoolProvider- Parameters:
threads- the number of threadsthreadNamePrefix- a label to identify the threads; useful for profiling.- Returns:
- the new ExecutorService
-
isScheduledExecutorBlocking
public boolean isScheduledExecutorBlocking()
- Specified by:
isScheduledExecutorBlockingin interfaceThreadPoolProvider- Returns:
trueif the executors returned byThreadPoolProvider.newScheduledExecutor(int, java.lang.String)may block when submitting a task;falseif they never block (e.g. they throw anRejectedExecutionException).
-
-