17.4 Enter the Executor
A thread is always required for the concurrent execution of a Runnable. Although the concurrent processing of program code isn’t possible without threads, the two are strongly connected in programming. Thus, ideally, the Runnable is somewhat separated from the actual processing thread. Several reasons exist for this suggestion:
-
As early as during the creation of a Thread object, the Runnable object must be passed in the Thread constructor. You cannot create the Thread object, then later assign the Runnable object via a setter and then start the thread using start() .
-
If start() is called twice on the Thread object, the second call results in an exception. Thus, a created thread can’t process a Runnable twice by ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access