• Post Reply Bookmark Topic Watch Topic
  • New Topic

More on threads and access to variables

 
Vernon Gibson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!