The Java ExecutorService Interface (Parts 1 and 2)

preview_player
Показать описание
This video gives an overview of the Java Executor Service interface, focusing on the interfaces, classes, and methods it defines.
Рекомендации по теме
Комментарии
Автор

0:27 ExecutorService extends Executor interface
1:12 Runnable - "one-way" task that doesn't return a result
1:21 Callable - "two-way" task that returns a result
1:39 typically used to run asynchronous tasks
1:47 Callable implements the Active Object pattern
1:50 Active object pattern allows you to decouple the thread that invokes the method from the thread that execute the method 2:00 and it also allows your to get the results back
2:04 Future - the way you get the result back
2:20 represents result of asynchronous two-way tasks
2:39 analogy of Future
3:13 you can cancel the task with Future
4:36 FutureTask
5:20 RunnableFuture
6:53 ExecutorService also forms The basis for key Java executor framework subclass
8:10 key methods of ExecutorService
8:27 ExecutorService can be used in two ways:
8:30 used as a more powerful Executor
8:40 execute() - one-way
8:55 submit - asynchronous two-way methods
9:20 submit supports "synchronous future" processing model
9:37 Future.get() blocks until task completes successfully
10:23 execute a group of tasks - invokeAll, invokeAny
10:51 invokeAll and invokeAny block until all the processing is finished
14:19 shutdown operations
14:34 initiate a shutdown
14:58 shutdown immediately - shutdownNow().
15:05 it doesn't let anybody in 15:08 tries to shut down all running computations by INTERRUPTING
15:25 analogy (library closing)
15:39 15:45 if there are tasks waiting to run during shutdownNow(), the waiting tasks will be returned
15:55 check to see if the executor service is shut down - isShutdown()
16:04 shutdown means is shut down in process
16:06 terminate means has it shutdown
16:09 awaitTermination
17:00 block until all the tasks complete

ruixue
Автор

Prof Doug, when Shutdown()/ShutdownNow() APIs are invoked, and
some of the submitted tasks don't listen to interrupts and they do some computations inside while(true) loop, ExecutorService.isTerminated will return with False and also awaitTermination(timeout) API will return false, right?

Is there any way to cancel such kind of tasks running inside while(true) loop and they don't respond to interrupts.
One option could be to make the worker thread daemon.

SanjeevKumar-hjfb