• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

shared resourec + class devel declaration

 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a Test class that defines instance variable. If you have more than one thread and each one is operating on different instance of Test, will that instance variable still be a shared resource? I mean will there be any race condition in this case.

If all thread operate on same instance of Test, then instance variable will be shared one just like servlet should not have any class level declaration.

Thanks & Regards

Naseem
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Naseem Khan:
There is a Test class that defines instance variable. If you have more than one thread and each one is operating on different instance of Test, will that instance variable still be a shared resource? I mean will there be any race condition in this case.



Instance variables are just that -- instance variables. Each instance of the (Test) class that has that variable will have its own instance of the variable. Changing the reference in one Test class will *not* affect another instance of the Test class.

As for whether "there be any race condition", it's not that simple. While each instance of the Test class may have its own copy of the variable, the variable may be a class that contain static variables. So, any race condition is still dependent on how the instance variable is used.

Henry
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




You mean to say that in this case, even if different thread has different instances of Test, but still race condition could be possible because Test has-a Test2 which has a static declaration.

Am I right?

Regards


Naseem
[ July 03, 2006: Message edited by: Naseem Khan ]
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic