One way to create thread is to pass a object that implements Runnable Interface to a Thread constructor as mentioned in Java Multithreading Approaches (Java Concurrency - Part 1): public class MyRunnable implements Runnable{
0 Comments
With regards to java concurrency, when reading some API documentation (e.g. java.util.concurrent), there's the term "non-blocking" and "blocking." In computer science, non-blocking means:
In Java concurrency, ForkJoinPool uses a work-stealing multi-threading framework which works well for executing tasks of uneven distribution of chunk sizes. Before you read on, you need to know Java Multithreading Approaches first.
A ForkJoinPool implements ExecutorService but it differs from other (I'll refer them as 'traditional') ExecutorService mainly by virtue of employing work-stealing - all threads in the pool attempt to find and execute subtasks created by other active tasks. It automatically balance the task load between threads, while traditional ThreadPoolExecutor has no mechanism for such kind of load balancing. If no available worker thread is available, tasks will be blocked until a thread becomes available to steal work from those workers who are busy. In Java concurrency, there are two low level concurrency implementations in Java to create a thread - extend the Thread class or implement Runnable interface. These basic approaches neither return value from the thread nor throw exception should anything goes wrong. There's a third approach since Java 1.5 - use Java Concurrency package which supports to receive return values from thread execution.
|
Categories
All
Archives
May 2020
|