Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

How to get reference of object which calls the method?

Tue Oct 21, 2008 7:42 pm

How to get reference of object which calls the method?

I have a Thread class which is singleton, so I don't want to allow
other objects to run run() method of my class. I cannot make it private
also. So maybe I can check who is calling run() method?



Re: How to get reference of object which calls the method?

Tue Oct 21, 2008 7:43 pm

run () is never called directly by application code. Rather, application
code calls start (), and the JVM starts a thread and calls run () (the
fact that the JVM calls run () is why it must be public). If the
application code calls run () directly, then Java Threads are not being
used, and run () is just another method call.

Also, it is illegal for start () to be called more than once, so there
is no need for a Thread to be a singleton, nor for the code to be
synchronized, nor for any "caller checking" code to exist.

Post a reply
  Related Posts  to : How to get reference of object which calls the method?
 object reference be cast to an interface reference     -  
 Method Parameters,,,is it by value or reference???     -  
 What exact mean by Object, Reference and Instance?     -  
 use out object in a method at jsp     -  
 Help in C# sample, SDP in VoIP SIP calls     -  
 Can i track calls from mobile phones     -  
 Reference Parameters     -  
 unset reference variables     -  
 Reference between two schemas in oracle     -  
 Reference Array by index     -