This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread start Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread start" Watch "Thread start" New topic
Author

Thread start

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi, Why I am getting Runtime Exception as given below.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3401
    
    9
You are getting a runtime exception because you can start the thread only once. You are starting the same thread, because the getInst() method returns the same (static) Thread, regardless of what object you call it on.

The reason you are getting a stack overflow error, is because if you remove the static modifier, when the tr member is initialized, that new member will also initialize it's internal tr reference, which in turn will initialize it's initial reference, etc, etc, ad infinitum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread start
 
Similar Threads
Thread
Using non-static object as lock in Threads PRoblem
Problem : Threads ; Reference Cert Pal
Threads - static variable and static/non static method execution
synchronized method