package com.habby.test.test2;
public class HabbyTest {
public static int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public static void main(String[] args) {
new Thread(new Runnable() {
@Override
public void run() {
synchronized(array) {
for (int i = 0; i < array.length; i += 2) {
System.out.println("Thread even: " + array[i]);
array.notify();
try {
array.wait();
} catch (InterruptedException e) {
}
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
synchronized (array) {
for (int i = 1; i < array.length; i += 2) {
System.out.println("Thread odd: " + array[i]);
array.notify();
try {
array.wait();
} catch (InterruptedException e) {
}
}
}
}
}).start();
}
}