In this concept called Java Thread, we are going to refer about two basic units of execution Process and Thread. Java threads also has concurrency programming concerned with it. For more information Join the Java training institute.
Program or Application is the view of the self possessed execution environment called the process. There are multiple process inside the program. There are different classes and programs called process and the Java runtime environment runs as this.
Lightweight process is the other name for Thread. For creating and existing in the process there are only less resources required by the process and the process resource is shared by the threads.
Read More : Java Training Institute
3) Java Thread Example
Main Thread is the only thread that every Java application has. Like memory management, signal processing, system management there are lots of Java threads running in the memory. The first Java thread also called as main is considered from the application point of view and there are multiple threads that can be created.
In a single program if there are two or more executing concurrent threads called Multi threading. Only one thread can be executed at a time and time slicing is the OS feature for sharing processor time between threads and processes.
Advantages of Java Thread
1) When compared to processes, Java threads are less in weight and for the resource creating a thread, less time is required.
2) The cost is less in context switching between threads when compared to processes.
3) When compared to process communication, thread intercommunication is quite easy.
Read More : Trends In Java Tools and Technologies
Runnable Vs Thread
If there is more functionality offered than simply running as Thread, you need to apply Runnable Interface for offering a method to run it as Thread. Thread class can be extended if you need class only goal for running as Thread.
Java aids implementing lots of interfaces and therefore implementing Runnable is preferred. There is a possibility of extending other class if you can extend Thread class.
Thus join the java training class to make your career in this field.