Please enable JavaScript.
Coggle requires JavaScript to display documents.
Java Multithreading (Make a Class Immutable (• If fields are not of a…
Java Multithreading
Make a Class Immutable
-
• The class itself should be declared final in order to prevent subclasses to violate the principle of immutability.
-
-
Fixed Thread Pool
Description
• A thread pool that reuses a fixed number of threads.
• Submitted tasks are put in a queue until a thread is available.
• If a thread fails, a new one takes its place.
• The threads exist until the pool is explicitly shutdown.
-
Methods
Future<T> ExecutorService.submit(Callable<T> task) - Submits a value-returning task for execution and returns a Future representing the pending results of the task.
void ExecutorService.shutdown() - Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Idempotent operation.
void Executor.execute(Runnable command) - Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
ThreadLocal Class
Description
• The class provides thread-local variables i.e. each thread has its own, independently initialized copy of the variable.
• ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread
-
-
Fork/Join Framework
Description
A thread pool that takes special kinds of tasks, namely the ForkJoinTask. This class implements Future and therewith methods like get(), cancel() and isDone(). The fork() method starts an asynchronous execution, a call of join() waits until the task has finished and retrieve its result.
Base class: java.util.concurrent.ForkJoinPool
-
-