Hello all,
I have a
thread and shared resource synchronization problem.
Here's the skinny on what I want my program to do.
I have a class that extends Thread, call it class X.
The class X object takes a
String array and an integer representing the position in the array to update as the input parameters of its constructor. (This String array will be the shared resource between all instances of class X)
I also have a
Servlet that creates four instances of this X class and passes each instance of X the same array reference but different integer values for the array position value ranging from (0 to 3).
I want to ensure that each class X object updates only one position of the array and that all X objects update the positions, as represented by the position value passed to their constructors, in the array before I attempt to access the array in order to display its contents to a user. (Since there are 4 X objects the shared String array is of size = 4)
I have tried a few different approaches with no luck. I can't seem to get each object to update the array. I may get two to do an update at best.
Does anyone have a design approach that would guarantee that each array element is updated by the appropriate thread?
Thanks in advance,
Chad Schmidt