• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads -- Calling start() twice (from constructor and main())

 
Vigneshwari Chandrasekaran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Added code tags - see UseCodeTags for details]

In this code, start() is called twice (one inside constructor & another from main()) , but on the same instance.
Actually in case of calling start() more than once, we will be getting IllegalMonitorStateException right?
Then how is it possible to get the code executed with output "main22".
I am really confused about this output. Why is this such exceptional case for calling a method from constructor?
Please anybody explain.
Thanks!!
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vigneshwari. Welcome to the Ranch!

Are you sure they're being called on the same instance? How many Thread objects do you think you are creating in that code?
 
Vigneshwari Chandrasekaran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Hi Vigneshwari. Welcome to the Ranch!

Are you sure they're being called on the same instance? How many Thread objects do you think you are creating in that code?


I just got clear with it.. My friend helped me.
The start() call within constructor is executed by main Thread. And that in main() is by the instance created. Hence no exception..

Thanks for the reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic