/** * Test simulate for GLASSFISH-16707. * * @author Shing Wai Chan */ import java.util.*; import java.util.concurrent.*; public class CHMTest { static Map map = new ConcurrentHashMap(); static int ARRAY_SLEEP = 5; static int ADD_SLEEP = 4; static int REMOVE_SLEEP = 6; static class ArrayRunnable implements Runnable { public void run() { Thread t = Thread.currentThread(); System.out.println("ArrayRunnable run ..." + t); while (true) { try { t.sleep(ARRAY_SLEEP); } catch(Exception ex) { } map.values().toArray(new String[0]); } } } static class AddRunnable implements Runnable { public void run() { Thread t = Thread.currentThread(); int i = 0; System.out.println("AddRunnable run ..." + t); while (true) { try { t.sleep(ADD_SLEEP); } catch(Exception ex) { } String iStr = Integer.toString(i); map.put(iStr, iStr); i++; } } } static class RemoveRunnable implements Runnable { public void run() { Thread t = Thread.currentThread(); int i = 0; System.out.println("RemoveRunnable run ..." + t); while (true) { try { t.sleep(REMOVE_SLEEP); } catch(Exception ex) { } if (i % 10 == 0) { String iStr = Integer.toString(i); map.remove(iStr); } i++; } } } public static void main(String args[]) { int numOfThreads = 60; // multiple of 3 Thread[] thrs = new Thread[numOfThreads]; for (int i = 0; i < (numOfThreads / 3); i++) { thrs[3 * i] = new Thread(new ArrayRunnable()); thrs[3 * i + 1] = new Thread(new AddRunnable()); thrs[3 * i + 2] = new Thread(new RemoveRunnable()); } for (Thread thr : thrs) { thr.start(); } } }