public static Lock lock = new ReentrantLock();
public static int count = 1;
public static Thread thread1 = new Thread(() -> {
while (count < 100) {
lock.lock();
if (count % 3 == 0) {
System.out.println("A:" + count);
count ++;
}
lock.unlock();
}
});
public static Thread thread2 = new Thread(() -> {
while (count < 100) {
lock.lock();
if (count % 5 == 0) {
System.out.println("B:" + count);
count ++;
}
lock.unlock();
}
});
public static Thread thread3 = new Thread(() -> {
while (count < 100) {
lock.lock();
if (count % 5 != 0 && count % 3 != 0) {
System.out.println("C:" + count);
count ++;
}
lock.unlock();
}
});
public static void main (String[] args) {
thread1.start();
thread3.start();
thread2.start();
}