use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testBuildMutateBuild.
public void testBuildMutateBuild() {
ThreadFactory factory1 = builder.setPriority(1).build();
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
ThreadFactory factory2 = builder.setPriority(2).build();
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
assertEquals(2, factory2.newThread(monitoredRunnable).getPriority());
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testDaemon_true.
public void testDaemon_true() {
ThreadFactory factory = builder.setDaemon(true).build();
Thread thread = factory.newThread(monitoredRunnable);
assertTrue(thread.isDaemon());
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testPriority_custom.
public void testPriority_custom() {
for (int i = Thread.MIN_PRIORITY; i <= Thread.MAX_PRIORITY; i++) {
ThreadFactory factory = builder.setPriority(i).build();
Thread thread = factory.newThread(monitoredRunnable);
assertEquals(i, thread.getPriority());
}
}
use of java.util.concurrent.ThreadFactory in project guava by hceylan.
the class ThreadFactoryBuilderTest method testThreadFactory.
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);
}
use of java.util.concurrent.ThreadFactory in project guava by google.
the class MoreExecutorsTest method testGetExitingExcutorService_executorDelegatesToOriginal.
public void testGetExitingExcutorService_executorDelegatesToOriginal() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
ThreadFactory threadFactory = mock(ThreadFactory.class);
when(executor.getThreadFactory()).thenReturn(threadFactory);
application.getExitingExecutorService(executor).execute(EMPTY_RUNNABLE);
verify(executor).execute(EMPTY_RUNNABLE);
}
Aggregations