Can we start a thread twice in java

Previous
Next

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:

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

You can go through core java interview questions for beginners and experienced for more such questions.

Previous
Next


Related posts

Add Comment