I've learned that every class byte code is been loaded to the memory once for each class loader, thus when a thread is executing the byte code of some method, and another thread comes along?
1 thread -> 1 instance - of class Foo == no problem.
X threads -> 1 instance - of class Foo == need to be handled this is clear.
X threads -> X respective instances - of class Foo == ????
should I make sure nothing is messed up in the method? if the method uses a instance level variables, can I be sure it will use the right ones?
Update:
I see my question was not clear to some, here is an example with numbers
I have an object of class type Foo which has no synchronization!!
I have 5 instances of that Foo with 5 threads running for/in each of them, and accessing instance level parameters for example:
class FOO {
private SomeObject someObject=new SomeObject();
private void problematicMethod(Data data) {
someObject.doSomethingWithTheData(data);
data.doSomethingWithSomeObject(someObject);
// any way you want it use the data or export the data
}
}
I'm asking is there a problem here, since there is only 1 byte code of this class and 5 instances of this object that access this byte code, so if I want to prevent them from overlapping on the same byte code, what should I do?
Thanks, Adam.