Okay so I am having trouble with this maybe i have just been thinking too long or am dumb but here is what i have and what i am trying to do:
Update- code all fixed no more run problems.
public class myClass program {
int [] w = null;
int [] x = null;
Thread T = null;
public static void main(String [] args){
x = new int[5];
w = new int[5];
// here i am trying to invoke a new thread passing the index
// of my array, then incrementing the index each time i create a new thread
// the purpose is to fill each index each time the new thread runs.
for(int i = 0; i < w.length; i ++){
// T = new Thread(new myThreadClass(w[i])); // only passes 0 take this out and
T = new Thread( new myThreadClass(i)); // pass i so the position changes
T.start();
try{
Thread.sleep(100);
}catch(Exception e){}
}
}
in my separate class myThreadClass.java i have the following:
public class myThreadClass extends Thread{
int [] w = null;
int position = 0;
int value = 1;
public myThreadClass(int p){
this.position = p
w = myClass.w;
}
@Override
public void run(){
// synchronize the thread so there is no memory cache problems
//
synchronized(w){
w[position] = value;
}
}
}
when i print out the output of w from myClass:
i get w = 1 0 0 0 0
but i want w = 1 1 1 1 1
EDITED- i am now getting the right output - check the code for changes