1. What is Thread
· Java Thread is a lightweight process that executes some task.
· Thread is independent sequential flow of execution.
· The process of creating multiple threads for executing independent tasks concurrently to complete their executions in short time by using CPU ideal time effectively called as multithreading.
· Java provides multithreading support with the Thread class and an application can create multiple threads executing concurrently.
2. Why thread are called as lightweight process
· Multitasking is heavy weight because switching between one process to another process is stored at a separate address.
· Multithreading is light weight process because switching between contexts is fast because each thread is stored in same process.
· Also threads within a process share the same address space because of which cost of communication between threads is low as it is using the same code section, data section and OS resources, so these all features of thread makes it a "lightweight process"
3. What makes Java application is concurrent
· This class is the basis of all concurrency concepts in java.
4. Java Concurrency evolution
· As per JDK 1.x release, initially java team introduced following classes and interfaces
1. Java.lang.Thread
2. Java.lang.Runnable
3. Java.lang.ThreadGroup
4. Java.lang.Process
5. Java.lang.ThreadDeath
· In JDK 1.4, some changes added in JVM level like suspend, resume multiple threads in single call
· In JDK 1.5, first big release after JDK 1.x; and it had included multiple concurrency utilities.
· Executor, semaphore, mutex, barrier, latches, concurrent collections and blocking queues; all were included in this release itself.
· The biggest change in java multi-threading applications cloud happened in this release.
· In JDK 1.7, added support for ForkJoinPool which implemented work-stealing technique to maximize the throughput. Also Phaser class was added.
· JDK 1.8 is largely known for Lambda changes, but it also had few concurrency changes as well.
· Two new interfaces and four new classes were added in java.util.concurrent package e.g. CompletableFuture and CompletionException.
No comments:
Post a Comment