Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Briefly explain the code in each area with a /*comment*/ above it public class ThreadLister { ThreadGroup rootThreadGroup = null; /* Getting the root

Java: Briefly explain the code in each area with a /*comment*/ above it

public class ThreadLister { ThreadGroup rootThreadGroup = null; /* Getting the root thread group*/ ThreadGroup getRootThreadGroup( ) { if ( rootThreadGroup != null ) return rootThreadGroup; ThreadGroup currentThreadGroup = Thread.currentThread( ).getThreadGroup( ); ThreadGroup parentThreadGroup; while ( (parentThreadGroup = currentThreadGroup.getParent( )) != null ) currentThreadGroup = parentThreadGroup;

rootThreadGroup = currentThreadGroup;

return rootThreadGroup; }

/* Getting a list of all thread groups*/ ThreadGroup[] getAllThreadGroups( ) { final ThreadGroup root = getRootThreadGroup( );

/* Comment Here */ int alloc = root.activeGroupCount( );

/* Comment Here */ int n = 0; ThreadGroup[] groups; do { /* Comment Here */ alloc *= 2; groups = new ThreadGroup[alloc];

/* Comment Here */ n = root.enumerate(groups, true); } while (n == alloc);

/* Comment Here */ ThreadGroup[] allGroups = new ThreadGroup[n+1];

/* Comment Here */ allGroups[0] = root;

/* Comment Here */ System.arraycopy( groups, 0, allGroups, 1, n );

return allGroups; }

public static void main(String[] args) { new CreateThreadGroups(); ThreadLister groups = new ThreadLister();

/* Getting a thread group by name */ ThreadGroup[] groupList = groups.getAllThreadGroups();

/* Comment Here */ for (int i = 0; i < groupList.length; i++) { /* Comment Here */ Thread list[] = new Thread[groupList[i].activeCount() * 2]; groupList[i].enumerate(list, false); /* Comment Here */ System.out.println(groupList[i].getName()); for (int j = 0; j < list.length; j++) { if (list[j] != null) System.out.println("\t"+list[j].getName()+":"+list[j].getId()+":"+list[j].getState()+":"+list[j].isDaemon()); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science Project Ideas In Health Care Volume 1

Authors: Zemelak Goraga

1st Edition

B0CPX2RWPF, 979-8223791072

More Books

Students also viewed these Databases questions