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?
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.
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.