I’m reading about threads and in many books is said that Java support threads at language level and at a high-level trough the java.util.concurrent package.
What does it meaning supporting thread at language level?
I think Erlang is a language that support thread at language level…
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
synchronizedandvolatilekeywords. 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 thejava.util.concurrentpackage, 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 withCallableandFuture, 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,synchronizedandRunnable(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.