ThreadFactoryFactory { static public synchronized ThreadFactory getThreadFactory(String name) { PooledFactory p = factory.get(name); if (p == null) { p = new PooledFactory(name); factory.put(name, p); } return p.getFactory(false); }  static synchronized ThreadFactory getThreadFactory(String name); static synchronized ThreadFactory getDaemonThreadFactory(String name);  }
@Test public void requireThatFactoryCreatesCorrectlyNamedThreads() { Thread thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner()); assertEquals("a-1-thread-1", thread.getName()); thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner()); assertEquals("a-2-thread-1", thread.getName()); thread = ThreadFactoryFactory.getThreadFactory("b").newThread(new Runner()); assertEquals("b-1-thread-1", thread.getName()); ThreadFactory factory = ThreadFactoryFactory.getThreadFactory("a"); thread = factory.newThread(new Runner()); assertEquals("a-3-thread-1", thread.getName()); thread = factory.newThread(new Runner()); assertEquals("a-3-thread-2", thread.getName()); thread = factory.newThread(new Runner()); assertEquals("a-3-thread-3", thread.getName()); }