0

When a thread is created in Java, its state is new. When we start the thread, it checks for the thread state and if thread state is not new, it throws IllegalStateException. So, if we try to start a thread twice, it throws exception for the second call.

Why was this limitation added?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Prashant
  • 152
  • 1
  • 16
  • See also: http://stackoverflow.com/questions/10042457/why-java-doesnt-support-restarting-a-thread – assylias Sep 03 '15 at 12:56
  • When you read the linked answers, remember that a `Thread` is not the same thing as a _thread_. A (little-t) thread is an independent execution of your code. A (Big-T) `Thread` is an object that can be used to start, and manage the life cycle of a little-t thread. It's like, suppose you write code for an insurance company, and you define a (Big-A) `Accident` class to represent a (little-a) accident. Somebody asks, "Why can't I re-use an `Accident`?" Well, a (little-a) accident can only happen once, right? – Solomon Slow Sep 03 '15 at 19:27
  • What if you write a code for a Restaurant and define (Big-S) Serve class to represent a (little-s) serve. You can serve more than once I think. – Prashant Sep 04 '15 at 09:12

0 Answers0