Code example for AtomicInteger

Methods: getAndDecrement

0
        final AtomicReference<Throwable> errorRef = new AtomicReference<>(null);
 
        Runnable forwardTask = new Runnable() {
            public void executeOrDelay() { 
                EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
                if (eventQueue.peekEvent() == null || counter.getAndDecrement() <= 0) {
                    try { 
                        task.run();
                    } catch (Throwable ex) {
                        errorRef.set(ex);
                    } finally { 
                        doneSignal.signal();
                    } 
                } 
                else { 
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override 
                        public void run() { 
                            executeOrDelay(); 
                        } 
                    });