NameableThreadFactory implements ThreadFactory { public NameableThreadFactory(final String name) { SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); namePrefix = name + "-"; } NameableThreadFactory(final String name); Thread newThread(Runnable r);  }
@Test public void testNameableThreadFactory() { ThreadFactory tf = new NameableThreadFactory(null); Thread thread = tf.newThread(null); assertEquals("null-1", thread.getName()); tf = new NameableThreadFactory(THREAD_NAME); thread = tf.newThread(null); assertEquals(THREAD_NAME + "-1", thread.getName()); assertEquals(Thread.NORM_PRIORITY, thread.getPriority()); assertFalse(thread.isDaemon()); assertEquals(Thread.currentThread().getThreadGroup(), thread.getThreadGroup()); }