1.

What Is Executors Class?

Answer»

Executors class provide factory and utility methods for Executors framework classes LIKE Executor, ExecutorService, ScheduledExecutorService, ThreadFactory, and Callable.

THOUGH you can use ThreadPoolExecutor and ScheduledThreadPoolExecutor directly, but the best way to get an executor is to use one of the static factory methods provided by the Executors utility class.

Some of the factory methods -

  • static ExecutorService newCachedThreadPool() - Creates a thread POOL that creates new threads as needed, but will reuse previously constructed threads when they are available.
  • static ExecutorService newFixedThreadPool(int numThreads) - Creates a thread pool that reuses a fixed number of threads.
  • static ScheduledExecutorService newScheduledThreadPool(int numThreads) - Creates a thread pool that can schedule COMMANDS to run after a given delay, or to execute periodically.
  • newSingleThreadExecutor() - Creates an Executor that uses a single worker thread operating off an unbounded queue.

As EXAMPLE -

ExecutorService ex = Executors.newFixedThreadPool(2);

Executors class provide factory and utility methods for Executors framework classes like Executor, ExecutorService, ScheduledExecutorService, ThreadFactory, and Callable.

Though you can use ThreadPoolExecutor and ScheduledThreadPoolExecutor directly, but the best way to get an executor is to use one of the static factory methods provided by the Executors utility class.

Some of the factory methods -

As example -

ExecutorService ex = Executors.newFixedThreadPool(2);



Discussion

No Comment Found