Skip to content

Commit

Permalink
Removed mGroup from NamedThreadFactory (#15202)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrlw authored Mar 4, 2025
1 parent 07cb7da commit ace86c9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public NamedInternalThreadFactory(String prefix, boolean daemon) {
@Override
public Thread newThread(Runnable runnable) {
String name = mPrefix + mThreadNum.getAndIncrement();
InternalThread ret = new InternalThread(mGroup, InternalRunnable.Wrap(runnable), name, 0);
InternalThread ret = new InternalThread(InternalRunnable.Wrap(runnable), name);
ret.setDaemon(mDaemon);
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class NamedThreadFactory implements ThreadFactory {

protected final boolean mDaemon;

protected final ThreadGroup mGroup;

public NamedThreadFactory() {
this("pool-" + POOL_SEQ.getAndIncrement(), false);
}
Expand All @@ -45,22 +43,16 @@ public NamedThreadFactory(String prefix) {
public NamedThreadFactory(String prefix, boolean daemon) {
mPrefix = prefix + "-thread-";
mDaemon = daemon;
SecurityManager s = System.getSecurityManager();
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
}

@Override
public Thread newThread(Runnable runnable) {
String name = mPrefix + mThreadNum.getAndIncrement();
Thread ret = new Thread(mGroup, runnable, name, 0);
Thread ret = new Thread(runnable, name);
ret.setDaemon(mDaemon);
return ret;
}

public ThreadGroup getThreadGroup() {
return mGroup;
}

// for test
public AtomicInteger getThreadNum() {
return mThreadNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,4 @@ public void testGetThreadNum() {
assertNotNull(threadNum);
assertEquals(INITIAL_THREAD_NUM, threadNum.get());
}

@Test
public void testGetThreadGroup() {
NamedThreadFactory threadFactory = new NamedThreadFactory();
ThreadGroup threadGroup = threadFactory.getThreadGroup();
assertNotNull(threadGroup);
}
}

0 comments on commit ace86c9

Please sign in to comment.