What are Java Threads?
![]() |
In Pimpri Chinchwad Polytechnic in Computer Science Department gives full practical as well as theoretical knowledge about Threads in Java. Students develop their own programming knowledge about Java coding during practical sessions.
What’s the need of a thread or why we use Threads?
What happens when a thread is invoked?
When a thread is invoked, there will be two paths of execution. One path will execute the thread and the other path will follow the statement after the thread invocation. There will be a separate stack and memory space for each thread.
Risk Factor
Threads in Java
Java threads facility and API is deceptively simple:
Every java program creates at least one thread [ main() thread ]. Additional threads are created through the Thread constructor or by instantiating classes that extend the Thread class.
Thread creation in Java
Thread implementation in java can be achieved in two ways:
By extending thread class
void start(): Creates a new thread and makes it runnable.
void run(): The new thread begins its life inside this method.
![]() |
Example.
public class MyThread extends Thread {
public void run(){
System.out.println("thread is running...");
}
public static void main(String[] args) {
MyThread obj = new MyThread();
obj.start();
}
2) By Implementing Runnable interface
Example:
public class MyThread implements Runnable {
public void run(){
System.out.println("thread is running..");
}
public static void main(String[] args) {
Thread t = new Thread(new MyThread());
t.start();
}experts there.
Thread life cycle in java
![]() |
Pimpri Chinchwad Polytechnic is the best computer diploma engg college in Pune which provides vast knowledge about programming, where many sessions are conducted for students to gain knowledge about coding.
Blocking Threads
Grouping of threads
Target keywords: thread life cycle in java, java threading tutorial, using threads in java, javathread run.
These sessions are conducted under Java Programming Lecture in Pimpri Chinchwad Polytechnic which is one of the best college in Pune
Pallavi Maladkar
(Computer Department)
Pimpri Chinchwad Polytechnic