java thread program

Ads
 

java thread program

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

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 + "  ");
        }
    }
}

Ads









Related Tutorials/Questions & Answers:
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
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
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
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
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
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
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
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 program
java program  write a program showing two threads working simultaneously upon two objects(in theater one object "cut the ticket" and second object..."); Thread t1 = new Thread(obj1); Thread t2 = new Thread(obj2
Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking... is possible. In other words, a situation where a thread is waiting for an object lock that holds by second thread, and this second thread is waiting for an object
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
thread is a sequential path of code execution within a program.
thread is a sequential path of code execution within a program.   thread is a sequential path of code execution within a program. what is the meaning if sequential path of code execution? please explain me
a java program
a java program  Write a java program that accepts positive numbers... through the link may, this will be helpful for you http://www.roseindia.net/java/thread/java-multithreading-example.shtml Thanks
Java :Thread getPriority Example
Java :Thread getPriority Example In this tutorial you will learn how to get thread priority in java thread. Thread getPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
Explain the concept of thread priorities in Java.
Explain the concept of thread priorities in Java.  Explain the concept of thread priorities in Java
Java :Thread setPriority Example
Java :Thread setPriority Example In this tutorial you will learn how to set thread priority in java thread. Thread setPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
Java Program
Java Program  How to Write a Java program which read in a number of text files. It will use a thread to one file. Each line in the file will be put... out in the standard output. The program should be started like this: java
What Is Thread In Java?
, it is defined. Every Java program is run as a thread, thread is a sequential path of code execution within a program. Thread in Java follows a life cycle from its...What Is Thread In Java? In this section we will read about thread in Java
Java Thread : getState() Example
Java Thread : getState() Example This section explains how to get state of a thread  in java Thread. Thread  getState() : Suppose you want to know the state of the thread so for that Java Thread provides Thread.getState
Thread
Thread  What is multi-threading? Explain different states of a thread.   Java Multithreading Multithreading is a technique that allows a program or a process to execute many tasks concurrently (at the same time
Java :Thread Synchronization
Java :Thread Synchronization This section explains how to use concept of synchronization in java Thread. Thread Synchronization : . Java supports multi... of program. So for the multi-threaded application, synchronization of java

Ads