Total members 11894 |It is currently Sun Nov 24, 2024 9:41 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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?




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

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.

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  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     -  
 Id reference annotation relationship     -  
 unset reference variables     -  
 Reference between two schemas in oracle     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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