Managing Multiple threads accessing a single instance of a class
Hi,
i have to redesign a class, say X, in such a way that i manage multiple threads accessing a single instance of the class, we cannot create multiple instances of X. The class looks like this:
Class X{
boolean isACalled=false;
boolean isInitCalled=false;
boolean isBCalled=false;
A(){
isACalled=true;
}
Init(){
if(!isACalled)
A();
B();
C();
isInitCalled=true;
}
B(){
if(!isACalled)
A();
isBCalled=true;
}
C(){
if(!isACalled)
A();
if(!isBCalled)
B();
}//end of class
Init is the method that would be invoked on the single instance of this class.
Now i cannot keep the flags as instance variables coz different threads would have differrent status of these flags at the same time, hence i can make them local, but if i make them local to one method, the others won't be able to check their status, so the only solution i can think of is to place all the flags in a hashtable local to method INIT AND INITIALIZE ALL OF them to false, as init would call other methods, it would pass the hashtable reference as an additional parameter, the methods would set the flags in the hashtable and it would be reflectecd in the original hashtable, and so all the methods can have access to the hashtable of flags and can perform their respective checks and setting of flags.
This all would be local to one thread, so there's no question of flags of one thread mixin with the flags of some other thread.
My question is :
Is this the best way, would this work?
In java, everything is pass by value, but if i pass the hashtable reference, would the changes made inside the called method to the hashtable key-value would be visible in the original hashtable declared inside the calling method of which the hashtable is local variable?

