• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

More on threads and access to variables

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Trust God, but always tether your camel... to this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic