本文整理了Java中java.lang.Thread.getThreadGroup()
方法的一些代码示例,展示了Thread.getThreadGroup()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.getThreadGroup()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:getThreadGroup
[英]Returns the ThreadGroup to which this Thread belongs.
[中]
代码示例来源:origin: apache/incubator-dubbo
public NamedThreadFactory(String prefix, boolean daemon) {
mPrefix = prefix + "-thread-";
mDaemon = daemon;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}
代码示例来源:origin: apache/incubator-dubbo
public NamedThreadFactory(String prefix, boolean daemon) {
mPrefix = prefix + "-thread-";
mDaemon = daemon;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}
代码示例来源:origin: netty/netty
public DefaultThreadFactory(String poolName, boolean daemon, int priority) {
this(poolName, daemon, priority, System.getSecurityManager() == null ?
Thread.currentThread().getThreadGroup() : System.getSecurityManager().getThreadGroup());
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
DefaultThreadFactory(int threadPriority, String threadNamePrefix) {
this.threadPriority = threadPriority;
group = Thread.currentThread().getThreadGroup();
namePrefix = threadNamePrefix + poolNumber.getAndIncrement() + "-thread-";
}
代码示例来源:origin: jenkinsci/jenkins
private ThreadSorterBase() {
ThreadGroup tg = Thread.currentThread().getThreadGroup();
while (tg.getParent() != null) tg = tg.getParent();
Thread[] threads = new Thread[tg.activeCount()*2];
int threadsLen = tg.enumerate(threads, true);
for (int i = 0; i < threadsLen; i++) {
ThreadGroup group = threads[i].getThreadGroup();
map.put(threads[i].getId(), group != null ? group.getName() : null);
}
}
代码示例来源:origin: alibaba/canal
public NamedThreadFactory(String name, boolean daemon){
this.name = name;
this.daemon = daemon;
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Return the system thread group (sometimes also referred as "root thread group").
*
* @return the system thread group
* @throws SecurityException if the current thread cannot modify
* thread groups from this thread's thread group up to the system thread group
*/
public static ThreadGroup getSystemThreadGroup() {
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
while(threadGroup.getParent() != null) {
threadGroup = threadGroup.getParent();
}
return threadGroup;
}
代码示例来源:origin: apache/storm
public NettyRenameThreadFactory(String name) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
this.name = name;
}
代码示例来源:origin: springside/springside4
private NamedThreadFactory(String name) {
final SecurityManager s = System.getSecurityManager();
this.group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = name;
}
代码示例来源:origin: redisson/redisson
public DefaultThreadFactory(String poolName, boolean daemon, int priority) {
this(poolName, daemon, priority, System.getSecurityManager() == null ?
Thread.currentThread().getThreadGroup() : System.getSecurityManager().getThreadGroup());
}
代码示例来源:origin: alibaba/Sentinel
public NamedThreadFactory(String namePrefix, boolean daemon) {
this.daemon = daemon;
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
this.namePrefix = namePrefix;
}
代码示例来源:origin: neo4j/neo4j
@Deprecated
public NamedThreadFactory( String threadNamePrefix, int priority, Monitor monitor, boolean daemon )
{
this.threadNamePrefix = threadNamePrefix;
SecurityManager securityManager = System.getSecurityManager();
group = (securityManager != null) ?
securityManager.getThreadGroup() :
Thread.currentThread().getThreadGroup();
this.priority = priority;
this.daemon = daemon;
this.monitor = monitor;
}
代码示例来源:origin: apache/zookeeper
DaemonThreadFactory(String name, int firstThreadNum) {
threadNumber.set(firstThreadNum);
SecurityManager s = System.getSecurityManager();
group = (s != null)? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = name + "-";
}
代码示例来源:origin: sohutv/cachecloud
public NamedThreadFactory(String prefix, boolean daemo) {
mPrefix = prefix + "-thread-";
mDaemo = daemo;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}
代码示例来源:origin: sohutv/cachecloud
public NamedThreadFactory(String prefix, boolean daemo) {
mPrefix = prefix + "-thread-";
mDaemo = daemo;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}
代码示例来源:origin: alibaba/jstorm
NettyRenameThreadFactory(String name) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.name = name;
}
代码示例来源:origin: weibocom/motan
public DefaultThreadFactory(String prefix, boolean isDaemon, int priority) {
SecurityManager s = System.getSecurityManager();
this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = prefix + "-" + poolNumber.getAndIncrement() + "-thread-";
this.isDaemon = isDaemon;
this.priority = priority;
}
代码示例来源:origin: sohutv/cachecloud
public NamedThreadFactory(String prefix, boolean daemo) {
mPrefix = prefix + "-thread-";
mDaemo = daemo;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}
代码示例来源:origin: neo4j/neo4j
public static void logTrace( int skip, int limit, String fmt, Object... args )
{
if ( enabledAssertions() )
{
Thread thread = Thread.currentThread();
String threadName = thread.getName();
ThreadGroup group = thread.getThreadGroup();
String groupPart = group != null ? " in group " + group.getName() : "";
String message = "[" + threadName + groupPart + "] " + String.format( fmt, args );
TraceLog traceLog = new TraceLog( message );
printLimitedStackTrace( System.err, traceLog, skip, limit );
}
}
代码示例来源: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('-')));
}
内容来源于网络,如有侵权,请联系作者删除!