aspose file tools*
The moose likes Threads and Synchronization and the fly likes Threads -- Calling start() twice (from constructor and main()) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads -- Calling start() twice (from constructor and main())" Watch "Threads -- Calling start() twice (from constructor and main())" New topic
Author

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

Vigneshwari Chandrasekaran
Greenhorn

Joined: Jan 04, 2013
Posts: 16
[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

Joined: Apr 06, 2010
Posts: 4490
    
    8

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

Joined: Jan 04, 2013
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads -- Calling start() twice (from constructor and main())