Link to home
Start Free TrialLog in
Avatar of kkandasa
kkandasa

asked on

Constructor question

I would like multiple thread within a process to access
a common data.
I put the common data in a class and declared it static
i.e public class A {
           static int data1;
           static string data2;

           public synchronized int makechanges()
           {
              //make changes to static data...
           }
   }
my question regards the constructor for this class.
Obviously I would like to initialize data1 & data2 at
the start of the program.
But I can't initialize data1 & data2 in the constructor since each instantiation of this class by a
thread will reset the existing static data.
I could just set a flag as another static field in the
class to deal with this problem.
But is this the best way to get multiple threads to share data ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of msmolyak
msmolyak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial