@Test(timeout = 2000) public void testDefaultThreadFactoryNonStickyThreadGroupConstructor() throws InterruptedException { final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<DefaultThreadFactory>(); final AtomicReference<ThreadGroup> firstCaptured = new AtomicReference<ThreadGroup>(); final ThreadGroup firstGroup = new ThreadGroup("first"); final Thread first = new Thread(firstGroup, new Runnable() { @Override public void run() { factory.set(new DefaultThreadFactory("sticky", false, Thread.NORM_PRIORITY, null)); final Thread t = factory.get().newThread(new Runnable() { @Override public void run() { } }); firstCaptured.set(t.getThreadGroup()); } }); first.start(); first.join(); assertEquals(firstGroup, firstCaptured.get()); final AtomicReference<ThreadGroup> secondCaptured = new AtomicReference<ThreadGroup>(); final ThreadGroup secondGroup = new ThreadGroup("second"); final Thread second = new Thread(secondGroup, new Runnable() { @Override public void run() { final Thread t = factory.get().newThread(new Runnable() { @Override public void run() { } }); secondCaptured.set(t.getThreadGroup()); } }); second.start(); second.join(); assertEquals(secondGroup, secondCaptured.get()); }
@Override public Thread newThread(Runnable r) { Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet()); try { if (t.isDaemon() != daemon) { t.setDaemon(daemon); } if (t.getPriority() != priority) { t.setPriority(priority); } } catch (Exception ignored) { } return t; }
DefaultThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet()); try { if (t.isDaemon() != daemon) { t.setDaemon(daemon); } if (t.getPriority() != priority) { t.setPriority(priority); } } catch (Exception ignored) { } return t; } }
DefaultThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet()); try { if (t.isDaemon() != daemon) { t.setDaemon(daemon); } if (t.getPriority() != priority) { t.setPriority(priority); } } catch (Exception ignored) { } return t; } DefaultThreadFactory(Class<?> poolType);  DefaultThreadFactory(String poolName);  DefaultThreadFactory(Class<?> poolType, boolean daemon);  DefaultThreadFactory(String poolName, boolean daemon);  DefaultThreadFactory(Class<?> poolType, int priority);  DefaultThreadFactory(String poolName, int priority);  DefaultThreadFactory(Class<?> poolType, boolean daemon, int priority);  DefaultThreadFactory(String poolName, boolean daemon, int priority, ThreadGroup threadGroup);  DefaultThreadFactory(String poolName, boolean daemon, int priority); }
DefaultThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet()); try { if (t.isDaemon() != daemon) { t.setDaemon(daemon); } if (t.getPriority() != priority) { t.setPriority(priority); } } catch (Exception ignored) { } return t; } DefaultThreadFactory(Class<?> poolType);  DefaultThreadFactory(String poolName);  DefaultThreadFactory(Class<?> poolType, boolean daemon);  DefaultThreadFactory(String poolName, boolean daemon);  DefaultThreadFactory(Class<?> poolType, int priority);  DefaultThreadFactory(String poolName, int priority);  DefaultThreadFactory(Class<?> poolType, boolean daemon, int priority);  DefaultThreadFactory(String poolName, boolean daemon, int priority, ThreadGroup threadGroup);  DefaultThreadFactory(String poolName, boolean daemon, int priority); static String toPoolName(Class<?> poolType); @Override Thread newThread(Runnable r); }
DefaultThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { Thread t = newThread(FastThreadLocalRunnable.wrap(r), prefix + nextId.incrementAndGet()); try { if (t.isDaemon() != daemon) { t.setDaemon(daemon); } if (t.getPriority() != priority) { t.setPriority(priority); } } catch (Exception ignored) { } return t; } DefaultThreadFactory(Class<?> poolType);  DefaultThreadFactory(String poolName);  DefaultThreadFactory(Class<?> poolType, boolean daemon);  DefaultThreadFactory(String poolName, boolean daemon);  DefaultThreadFactory(Class<?> poolType, int priority);  DefaultThreadFactory(String poolName, int priority);  DefaultThreadFactory(Class<?> poolType, boolean daemon, int priority);  DefaultThreadFactory(String poolName, boolean daemon, int priority, ThreadGroup threadGroup);  DefaultThreadFactory(String poolName, boolean daemon, int priority); static String toPoolName(Class<?> poolType); @Override Thread newThread(Runnable r);  }