本文整理了Java中java.lang.Thread.isDaemon()
方法的一些代码示例,展示了Thread.isDaemon()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.isDaemon()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:isDaemon
[英]Tests if this thread is a daemon thread.
[中]测试此线程是否为守护进程线程。
代码示例来源:origin: netty/netty
@Override
public boolean isDaemon() {
return t.isDaemon();
}
代码示例来源:origin: redisson/redisson
@Override
public boolean isDaemon() {
return t.isDaemon();
}
代码示例来源:origin: ctripcorp/apollo
@Override
public boolean satisfy(Thread thread) {
return !thread.isAlive() || thread.isInterrupted() || thread.isDaemon();
}
});
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
@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;
}
}
代码示例来源:origin: apache/zookeeper
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;
}
}
代码示例来源:origin: lingochamp/FileDownloader
@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;
}
}
代码示例来源:origin: apache/storm
@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;
}
}
代码示例来源:origin: alibaba/jstorm
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;
}
}
代码示例来源:origin: apache/hbase
@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;
}
}
代码示例来源:origin: netty/netty
@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;
}
代码示例来源:origin: redisson/redisson
@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;
}
代码示例来源:origin: google/guava
public void testDaemon_false() {
ThreadFactory factory = builder.setDaemon(false).build();
Thread thread = factory.newThread(monitoredRunnable);
assertFalse(thread.isDaemon());
}
代码示例来源:origin: google/guava
public void testDaemon_true() {
ThreadFactory factory = builder.setDaemon(true).build();
Thread thread = factory.newThread(monitoredRunnable);
assertTrue(thread.isDaemon());
}
代码示例来源:origin: SonarSource/sonarqube
private static boolean isDaemon(String name) {
Thread t = getThread(name);
return (t != null) && t.isDaemon();
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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('-')));
}
代码示例来源:origin: google/guava
public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() {
TestApplication application = new TestApplication();
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
assertNotNull(application.getExitingScheduledExecutorService(executor));
assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* 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);
}
代码示例来源:origin: google/guava
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);
}
代码示例来源:origin: ReactiveX/RxJava
@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());
}
}
内容来源于网络,如有侵权,请联系作者删除!