aspose file tools
The moose likes Threads and Synchronization and the fly likes More on threads and access to variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "More on threads and access to variables" Watch "More on threads and access to variables" New topic
Author

More on threads and access to variables

Vernon Gibson
Ranch Hand

Joined: Dec 01, 2000
Posts: 35
We know that Class2, a thread started by Class1, has access to variables declared in Class1.
Now, if there are several instances of Class1 running on the same machine, can I be assured that a given Class2 will be referencing only the Class1 that started it?
Thanks,
Vernon
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Vernon Gibson:
Now, if there are several instances of Class1 running on the same machine, can I be assured that a given Class2 will be referencing only the Class1 that started it?

No. There is no isolation whatsoever between Threads.
The only way you can assure that your instance of Class2 will refer to the right instance of Class1 is by simply giving it the right Class1 object to work with (note that you will get this automatically if Class2 is a non-static inner class of Class1).
- Peter
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: More on threads and access to variables
 
Similar Threads
Please help me !!!!!answers for sun sample questions
Help with Code.. Help with Classes
accessing applet variable outside the applet
threads and access to variables
Accessing component from main class.... Help!