Q- Difference between Executors.newFixedThreadPool(1) and Executors.newSingleThreadExecutor()
newFixedThreadPool
/**
* @param nThreads the number of threads in the pool
* @return the newly created thread pool
* @throws IllegalArgumentException if {@code nThreads <= 0}
*/
public static ExecutorService newFixedThreadPool(int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
}
newSingleThreadExecutor
/**
* Unlike the otherwise equivalent
* <tt>newFixedThreadPool(1)</tt> the returned executor is
* guaranteed not to be reconfigurable to use additional threads.
*
* @return the newly created single-threaded Executor
*/
public static ExecutorService newSingleThreadExecutor() {
return new FinalizableDelegatedExecutorService
(new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()));
}
Related Tutorials
- Lock Interface In Concurrency API
- Lock In Java Example
- StampedLock With Examples
- Differences between Lock and Synchronized block
- Method And Block Synchronization In Java Example
- How To Create Custom Lock
- Fair Lock In Java Example
- Synchronization Vs Lock in java
- Thread Pool - ThreadPoolExecutor Example
- How To Create Custom Thread Pool
- How ConcurrentHashMap Works Internally
- newsinglethreadexecutor vs newfixedthreadpool
- Future Vs Completablefuture
- ExecutorService vs ExecutorCompletionService in Java
- Callable Interface Example
- CompletableFuture
- ExecutorCompletionService
- Method And Block Synchronization
- ConcurrentHashMap
- Differences Between Submit and Execute methods
- Difference Between Callable and Runnable Interface in Java
No comments:
Post a Comment