jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 3574
    
  14

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
Problem : Threads ; Reference Cert Pal
Using non-static object as lock in Threads PRoblem
Thread
synchronized method
Threads - static variable and static/non static method execution