Skip to content

Commit 3ad4e18

Browse files
committed
Update executorservice.md
1 parent 7c44ec1 commit 3ad4e18

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

notes/executorservice.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ This is why we don't want to create so many threads.
2626
We can create a pool of threads instead.
2727

2828

29-
### Different ways of creating `ExecutorService`s:
29+
### Different ways of creating `ExecutorService` Instance:
30+
31+
`ExecutorService` is an interface and its implementations can execute a `Runnable` or `Callable` class in an asynchronous way.
32+
33+
#### Using Executors
34+
35+
`Executors` is a utility class that provides factory methods for creating the implementations of the interface.
3036

3137
- Creates an Executor that uses a single worker thread operating off an unbounded queue:
3238

@@ -90,3 +96,13 @@ and is kept till a thread is available.
9096
});
9197
System.out.println("value from the async task : " + future.get());
9298
```
99+
100+
### How to shutdown `ExecutorService`?
101+
102+
There are three methods to invoke shutdown:
103+
104+
- `void shutdown()`: Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
105+
106+
- `List<Runnable> shutdownNow()`: Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
107+
108+
- `void awaitTermination()`:It blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

0 commit comments

Comments
 (0)