1 // Test atomic increment via synchronized blocks.
2 public class SyncTest implements Runnable {
6 // We cache the .class value; otherwise this code is
7 // slow enough that it will time out in some situations.
8 Object lock = SyncTest.class;
9 for (int n = 0; n < 1000000; n++)
15 public static void main(String[] args) {
16 SyncTest test = new SyncTest();
17 Thread[] thr = new Thread[4];
19 for (int n = 0; n < thr.length; n++) {
20 thr[n] = new Thread(test);
24 for (int n = 0; n < thr.length; n++) {
27 } catch (InterruptedException ex) {
31 System.out.println(counter == 1000000 * thr.length ?
32 "ok" : "fail: " + counter);