DefaultThreadFactoryTest Class — netty Architecture
Architecture documentation for the DefaultThreadFactoryTest class in DefaultThreadFactoryTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD eaa6bd91_82d8_cddc_06fc_0aeeb341228a["DefaultThreadFactoryTest"] 097461a1_b108_c494_aa51_6c634544fe73["DefaultThreadFactoryTest.java"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|defined in| 097461a1_b108_c494_aa51_6c634544fe73 d1d3ae34_c090_80b3_5d37_0b48f111ccc9["testDescendantThreadGroups()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| d1d3ae34_c090_80b3_5d37_0b48f111ccc9 848e2730_44ec_1d86_5a60_b70f6858121c["testDefaultThreadFactoryStickyThreadGroupConstructor()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| 848e2730_44ec_1d86_5a60_b70f6858121c acdf49b3_934e_cbb4_487b_ff54a875c5c5["testDefaultThreadFactoryInheritsThreadGroupFromSecurityManager()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| acdf49b3_934e_cbb4_487b_ff54a875c5c5 f0b3dd12_3d19_4b8d_e4bc_69ef17ce3819["runStickyThreadGroupTest()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| f0b3dd12_3d19_4b8d_e4bc_69ef17ce3819 1be54d70_05c9_ed46_9977_f24f74ac02ea["testDefaultThreadFactoryNonStickyThreadGroupConstructor()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| 1be54d70_05c9_ed46_9977_f24f74ac02ea ec6bff32_9e31_5571_2d1a_a9ce2f8161cf["testCurrentThreadGroupIsUsed()"] eaa6bd91_82d8_cddc_06fc_0aeeb341228a -->|method| ec6bff32_9e31_5571_2d1a_a9ce2f8161cf
Relationship Graph
Source Code
common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java lines 32–297
public class DefaultThreadFactoryTest {
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testDescendantThreadGroups() throws InterruptedException {
final SecurityManager current = System.getSecurityManager();
boolean securityManagerSet = false;
try {
try {
// install security manager that only allows parent thread groups to mess with descendant thread groups
System.setSecurityManager(new SecurityManager() {
@Override
public void checkAccess(ThreadGroup g) {
final ThreadGroup source = Thread.currentThread().getThreadGroup();
if (source != null) {
if (!source.parentOf(g)) {
throw new SecurityException("source group is not an ancestor of the target group");
}
super.checkAccess(g);
}
}
// so we can restore the security manager at the end of the test
@Override
public void checkPermission(Permission perm) {
}
});
} catch (UnsupportedOperationException e) {
Assumptions.assumeFalse(true, "Setting SecurityManager not supported");
}
securityManagerSet = true;
// holder for the thread factory, plays the role of a global singleton
final AtomicReference<DefaultThreadFactory> factory = new AtomicReference<DefaultThreadFactory>();
final AtomicInteger counter = new AtomicInteger();
final Runnable task = new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
};
final AtomicReference<Throwable> interrupted = new AtomicReference<Throwable>();
// create the thread factory, since we are running the thread group brother, the thread
// factory will now forever be tied to that group
// we then create a thread from the factory to run a "task" for us
final Thread first = new Thread(new ThreadGroup("brother"), new Runnable() {
@Override
public void run() {
factory.set(new DefaultThreadFactory("test", false, Thread.NORM_PRIORITY, null));
final Thread t = factory.get().newThread(task);
t.start();
try {
t.join();
} catch (InterruptedException e) {
interrupted.set(e);
Thread.currentThread().interrupt();
}
}
});
first.start();
first.join();
assertNull(interrupted.get());
// now we will use factory again, this time from a sibling thread group sister
// if DefaultThreadFactory is "sticky" about thread groups, a security manager
// that forbids sibling thread groups from messing with each other will strike this down
final Thread second = new Thread(new ThreadGroup("sister"), new Runnable() {
@Override
public void run() {
final Thread t = factory.get().newThread(task);
t.start();
try {
t.join();
} catch (InterruptedException e) {
interrupted.set(e);
Thread.currentThread().interrupt();
Source
Frequently Asked Questions
What is the DefaultThreadFactoryTest class?
DefaultThreadFactoryTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java.
Where is DefaultThreadFactoryTest defined?
DefaultThreadFactoryTest is defined in common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free