@Override public boolean isDaemon() { return t.isDaemon(); }
@Override public boolean isDaemon() { return t.isDaemon(); }
@Override public boolean satisfy(Thread thread) { return !thread.isAlive() || thread.isInterrupted() || thread.isDaemon(); } });
@Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); if (t.isDaemon()) t.setDaemon(false); t.setPriority(threadPriority); return t; } }
public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); if (!t.isDaemon()) t.setDaemon(true); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; } }
@Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); if (t.isDaemon()) t.setDaemon(false); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; } }
@Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, name + "-" + index.getAndIncrement(), 0); if (t.isDaemon()) { t.setDaemon(false); } if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } t.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER); return t; } }
public Thread newThread(Runnable runnable) { Thread t = new Thread(group, runnable, name + "-" + index.getAndIncrement(), 0); if (t.isDaemon()) t.setDaemon(false); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; } }
@Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); if (!t.isDaemon()) { t.setDaemon(true); } if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }
@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) { // Doesn't matter even if failed to set. } return t; }
@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) { // Doesn't matter even if failed to set. } return t; }
public void testDaemon_false() { ThreadFactory factory = builder.setDaemon(false).build(); Thread thread = factory.newThread(monitoredRunnable); assertFalse(thread.isDaemon()); }
public void testDaemon_true() { ThreadFactory factory = builder.setDaemon(true).build(); Thread thread = factory.newThread(monitoredRunnable); assertTrue(thread.isDaemon()); }
private static boolean isDaemon(String name) { Thread t = getThread(name); return (t != null) && t.isDaemon(); }
public void testGetExitingExecutorService_executorSetToUseDaemonThreads() { TestApplication application = new TestApplication(); ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1)); assertNotNull(application.getExitingExecutorService(executor)); assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon()); }
public void testThreadFactoryBuilder_defaults() throws InterruptedException { ThreadFactory threadFactory = builder.build(); Thread thread = threadFactory.newThread(monitoredRunnable); checkThreadPoolName(thread, 1); Thread defaultThread = Executors.defaultThreadFactory().newThread(monitoredRunnable); assertEquals(defaultThread.isDaemon(), thread.isDaemon()); assertEquals(defaultThread.getPriority(), thread.getPriority()); assertSame(defaultThread.getThreadGroup(), thread.getThreadGroup()); assertSame(defaultThread.getUncaughtExceptionHandler(), thread.getUncaughtExceptionHandler()); assertFalse(completed); thread.start(); thread.join(); assertTrue(completed); // Creating a new thread from the same ThreadFactory will have the same // pool ID but a thread ID of 2. Thread thread2 = threadFactory.newThread(monitoredRunnable); checkThreadPoolName(thread2, 2); assertEquals( thread.getName().substring(0, thread.getName().lastIndexOf('-')), thread2.getName().substring(0, thread.getName().lastIndexOf('-'))); // Building again should give us a different pool ID. ThreadFactory threadFactory2 = builder.build(); Thread thread3 = threadFactory2.newThread(monitoredRunnable); checkThreadPoolName(thread3, 1); assertThat(thread2.getName().substring(0, thread.getName().lastIndexOf('-'))) .isNotEqualTo(thread3.getName().substring(0, thread.getName().lastIndexOf('-'))); }
public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() { TestApplication application = new TestApplication(); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); assertNotNull(application.getExitingScheduledExecutorService(executor)); assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon()); }
/** * Helper method for testing whether the daemon flag is taken into account. * * @param flag the value of the flag */ private void checkDaemonFlag(final boolean flag) { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final Thread t = new Thread(); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).daemon( flag).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertTrue("Wrong daemon flag", flag == t.isDaemon()); EasyMock.verify(wrapped, r); }
public void testThreadFactory() throws InterruptedException { final String THREAD_NAME = "ludicrous speed"; final int THREAD_PRIORITY = 1; final boolean THREAD_DAEMON = false; ThreadFactory backingThreadFactory = new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(THREAD_NAME); thread.setPriority(THREAD_PRIORITY); thread.setDaemon(THREAD_DAEMON); thread.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER); return thread; } }; Thread thread = builder.setThreadFactory(backingThreadFactory).build().newThread(monitoredRunnable); assertEquals(THREAD_NAME, thread.getName()); assertEquals(THREAD_PRIORITY, thread.getPriority()); assertEquals(THREAD_DAEMON, thread.isDaemon()); assertSame(UNCAUGHT_EXCEPTION_HANDLER, thread.getUncaughtExceptionHandler()); assertSame(Thread.State.NEW, thread.getState()); assertFalse(completed); thread.start(); thread.join(); assertTrue(completed); }
@Test public void normal() { RxThreadFactory tf = new RxThreadFactory("Test", 1); assertEquals("RxThreadFactory[Test]", tf.toString()); Thread t = tf.newThread(Functions.EMPTY_RUNNABLE); assertTrue(t.isDaemon()); assertEquals(1, t.getPriority()); } }