package dev.banking.model;
import java.util.concurrent.atomic.AtomicInteger;

public class RaceConditionDemo {
    private static int normalCounter;
    private static AtomicInteger atomicCounter = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException{
        Thread [] thread = new Thread[1000];

        for (int i = 0; i < 1000; i++) {
            thread[i] = new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    normalCounter ++;
                    atomicCounter.incrementAndGet();
                }
            });
            thread[i].start();
        }
        for (Thread t : thread){
            t.join();
        }

        System.out.println("Normal: " + normalCounter);
        System.out.println("Atomic: " + atomicCounter);
    }
}
