Code example for AtomicInteger

Methods: compareAndSet

0
            while (!ai.compareAndSet(2, 3)) Thread.yield();
        } 
 
        public void thread2() { 
            System.out.println("t2");
            assertTrue(ai.compareAndSet(1, 2));
        } 
 
        @Override 
        public void finish() { 
            System.out.println("aa");
            assertEquals(ai.get(), 3);
        } 
    } 
 
    @Test 
    public void test() throws Throwable { 
//        TestFramework.runOnce(new MyMultithreadedTest()); 
        TestFramework.runManyTimes(new MyMultithreadedTest(), 100); 
    } 
}