No, Once you have started a
thread, it can not be started again. If you try to start thread again , it will throw IllegalThreadStateException
Lets understand with the help of example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package org.arpit.java2blog;
class FirstThread extends Thread {
public void run() {
System.out.println("Thread is running");
}
}
public class StartThreadAgainMain {
public static void main(String[] args) {
FirstThread ft = new FirstThread();
ft.start();
ft.start();
}
}
|
When you run above program , you will get below output:
|
Thread is runningException in thread "main"
java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:705)
at org.arpit.java2blog.StartThreadAgainMain.main(StartThreadAgainMain.java:16)
As you can see when we started thread twice, it threw IllegalThreadStateException.
|
If you try to start thread again , it will throw IllegalThreadStateException