import java.util.concurrent.atomic.AtomicInteger;
class Counter implements Runnable {
private static AtomicInteger i = new AtomicInteger(3);
public void run() {
System.out.print(i.getAndDecrement());
}
}
public class Test {
public static void main(String[] args) {
Thread t1 = new Thread(new Counter());
Thread t2 = new Thread(new Counter());
Thread t3 = new Thread(new Counter());
Thread[] threads = {t1, t2, t3};
for(Thread thread : threads) {
thread.start();
}
}
}
I ran this code many times and I always get 321 as the answer but I am not sure this code can get any other output.