Menu
Question Index
...

Output of the program will look like?

public class ThreadGroupDemo implements Runnable {
    public static void main(String[] args) {
        ThreadGroupDemo tg = new ThreadGroupDemo();
        tg.ThreadGroupExampleMethod();
    }
    public void ThreadGroupExampleMethod() {
        ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
        ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");
        Thread t1 = new Thread(pGroup, this);
        System.out.println("Starting " + t1.getName() + "...");
        t1.start();
        Thread t2 = new Thread(cGroup, this);
        System.out.println("Starting " + t2.getName() + "...");
        t2.start();
        Thread[] list = new Thread[pGroup.activeCount()];
        int count = pGroup.enumerate(list);
        for (int i = 0; i < count; i++) {
            System.out.println("Thread " + list[i].getName() + " found");
        }
    }
    public void run() {
        System.out.println(Thread.currentThread().getName() + " finished executing.");
    }
}


Output: 2 Threads starts, 2 Threads executing and there 1 or 2 not active threads found.
Output: 2 Threads starts, 2 Threads executing and there 2 active threads found.
Output: 2 Threads starts, 2 Threads executing but 0 active threads found.
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Thread Group

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App