To have threading supported at the language level means that the language provides first-class support for multi-threading, as opposed to just providing second-class support via class libraries.
In Java, threading is supported at the language level with the synchronized
and volatile
keywords. Using monitors and volatile fields are relatively low-level threading constructs - higher level constructs, such as generic Locks, Barriers, ThreadPools, Concurrent collections are found in the java.util.concurrent
package, along with low level atomic operations.
Threading in Java is more than a few keywords in the language. The Java Memory Model mandates the results of multi-threaded memory access, such as when changes by one thread are visible to other threads. This ensures correctly written threaded programs function as intended regardless of the underlying architecture (instruction re-ordering, cache-coherence polices etc..)
The original java class library provides threading support with java.lang.Thread
, representing a thread, and since JDk 1.2, java.lang.ThreadLocal
, representing thread-local variables. The original JDK also includes an abstract notion of an executable object - java.lang.Runnable
. The concurrency utils extend this with Callable
and Future
, which make creating asynchronous results much simpler than it would be coding with just the low level constructs.
While you can make do with volatile
, synchronized
and Runnable
(as many did prior to JDK 1.5) the classes provided by the concurrency utils make writing threaded programs much easier and with a greater chance of them being correct.