Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rajesh kumar swain
java thread program
1 Answer(s)      2 years and 9 months ago
Posted in : Java Interview Questions


write a java program to find out all the current running thread in a java program


Advertisement
View Answers

April 3, 2012 at 12:49 PM


public class RunningThreads{

public static void main(String[] args) {

        ThreadGroup group = Thread.currentThread().getThreadGroup();
        ThreadGroup gp;
        while ((gp = group.getParent()) != null) {
            group = gp;
        }
        findThreads(group, "");
    }
   public static void findThreads(ThreadGroup group, String str) {
        System.out.println(str + "Group[" + group.getName() +   ":" + group.getClass()+"]");
        int count = group.activeCount();
        Thread[] threads = new Thread[count*2 + 10]; 
        count = group.enumerate(threads, false);
        for (int i=0; i<count; i++) {
            Thread t = threads[i];
            System.out.println(str + "  Thread[" + t.getName() + ":" + t.getClass() + "]");
        }
        int ct = group.activeGroupCount();
        ThreadGroup[] groups = new ThreadGroup[ct*2 + 10];
        ct = group.enumerate(groups, false);

        for (int i=0; i<ct; i++) {
            findThreads(groups[i], str + "  ");
        }
    }
}


Related Tutorials/Questions & Answers:
java thread program
java thread program  write a java program to find out the current running thread in a java program   public class RunningThreads{ public...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
java thread program
java thread program  write a java program to find out all the current running thread in a java program   public class RunningThreads...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
Advertisements
sleep method in thread java program
sleep method in thread java program  How can we use sleep method in thread ?   public class test { public static void main(String...) { } } } } Output Delhi Bihar Goa Pune mumbai Description:- In this thread
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
java Thread
java Thread  what is purpose of Thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What are the high-level thread states
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
Thread in java
Thread in java  which method will defined in thread class
Java Thread
Java Thread Tutorials In this tutorial we will learn java Threads in detail. The Java Thread class helps the programmer to develop the threaded application in Java. Thread is simple path of execution of a program. The Java Virtual Machine
Java thread
Java thread  What is the use of serializable
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  Can we have run() method directly without start() method in threads
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference will provides you clear idea of java thread concept. http
a multithreaded program by creating a subclass of Thread
a multithreaded program by creating a subclass of Thread  I want... this OUTPUT thread1: Java thread1: is thread2: Java thread1: an thread2.... but mine not display like that output why ? My output : thread1: Java thread2
Java Thread Priority
Java Threads run with some priority There are Three types of Java Thread...() method. Java Thread Priority Example public class priority implements...++) System.out.println(x + " This is thread " + Thread.currentThread
Java Exception Thread
to Overcome this Thread Exception in Java Program In the preceding code, we... Java Exception Thread     ... the program. Many Thread run concurrently in the program. Multithread are those
Java Thread
sequential flow of control within a program. Programmer may use java thread mechanism... Java Thread       A java...;thread is a sequential path of code execution within a program. Each thread has
Java thread state
Java thread state  what is Static binding
Extending thread - Java Beginners
visit to : http://www.roseindia.net/java/thread/index.shtml Thanks...Extending thread  what is a thread & give me the programm of exeucte the thread   Hi friend, Thread : A thread is a lightweight
Thread - Java Beginners
the concept of thread, thread creation and use of threads in JAVA application?  Thread creation and use of threads in JAVA Java Resourcehttp://www.roseindia.net/java/thread/thread-creation.shtml
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
Java Thread
Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple threads for concurrent execution. Each thread has priority. You can also set
Java thread state
Java thread state  Difference between sleep and suspend
 

 

 

DMCA.com