Java EE threads

The EE concurrency utilities also provide a Java EE ThreadFactory, which creates ManageableThread instead of a plain thread. The main difference is that they provide an isShutdown() method, allowing you to know whether the current thread is shutting down and, thereby, exit the process if it is indeed shutting down. ManagedExecutors.isCurrentThreadShutdown() allows you to directly test this flag, handling the casting of the thread automatically. This means that a long running task can be implemented as follows:

while (running && !ManagedExecutors.isCurrentThreadShutdown()) {    process();}

You may think that testing only the thread state would be enough, but you still need an application state to ensure that you integrate with ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.