class PrintNumberTask implements Runnable {
Integer count;
Object lock;
PrintNumberTask(int i, Object object) {
this.count = i;
this.lock = object;
}
@Override
public void run() {
while (count <= 10) {
synchronized (lock) {
if (count % 2 == 0) {
System.out.println(count);
count++;
lock.notify();
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
System.out.println(count);
count++;
lock.notify();
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}