public class HashSyncMadness extends Thread { private long lastMessage = -1; public void run() { while (true) { synchronized (HashSyncMadness.class) { say( "I got the static lock" ); } } } private void say( String msg ) { if (System.currentTimeMillis() - lastMessage < 2000) { return; } System.out.println( "HashSyncMadness: " + Thread.currentThread().getName() + ": " + msg ); lastMessage = System.currentTimeMillis(); } public static void main( String[] args ) { // first create a bunch of us so that we can contend for the same monitor, then // create a bunch of VectorThrashers so that the hash_synchronization table is // gettting excercised. for (int i = 0; i < 3; ++i) { HashSyncMadness hsm = new HashSyncMadness(); hsm.start(); } for (int i = 0; i < 3; ++i) { VectorThrasher vt = new VectorThrasher(); vt.start(); } } }