Code example for AtomicInteger

Methods: getAndIncrement, set

0
        this.monitor = monitor;
        count = new AtomicInteger(0);
    } 
 
    public void run() { 
        if (count.getAndIncrement() == 5) {
            monitor.error(new Exception("An error was raised"));
            count.set(0);
        } else { 
            monitor.message("This is a message");
        } 
    } 
}