Question : Can we start a thread two times in Java?
Answered by : pragya-keshap
{"tags":[{"tag":"p","content":"No. We can call start() method only once on a thread in Java. If we\n"},{"tag":"p","content":"call it twice, it will give us exception"},{"tag":"p","content":""},{"tag":"textarea","content":"public class TestThreadTwice1 extends Thread{ \n public void run(){ \n System.out.println(\"running...\"); \n } \n public static void main(String args[]){ \n TestThreadTwice1 t1=new TestThreadTwice1(); \n t1.start(); \n t1.start(); \n } \n} ","code_language":"java"},{"tag":"p","content":"<a target=\"_blank\" href=\"https://www.javatpoint.com/can-we-start-a-thread-twice#:~:text=No.,time%2C%20it%20will%20throw%20exception.\">https://www.javatpoint.com/can-we-start-a-thread-twice#:~:text=No.,time%2C%20it%20will%20throw%20exception.</a>"},{"tag":"p","content":""}]}
Source : | Last Update : Sat, 11 Feb 23