public static void main(String[] args){
FillArray fa = new FillArray();
Thread t1 = new Thread(fa);
Thread t2 = new Thread(fa);
t1.start();
t2.start();
}
}
class FillArray implements Runnable{
int[] arr = new int[6];
Random r = new Random();
int count = 0;
public void run() {
synchronized(r){
while(count<arr.length){
int num = r.nextInt(20);
arr[count] = num;
count++;
try {
r.wait(500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
System.out.println(Arrays.toString(arr));
}
} |
|