java thread program

java thread program

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

View Answers

April 3, 2012 at 12:50 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
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
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What are the high-level thread states
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
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
Java Exception Thread
); ^ How to Overcome this Thread Exception in Java Program... Java Exception Thread     ... the program. Many Thread run concurrently in the program. Multithread are those
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
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 and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
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
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link...({});   Hi, There are two types of Thread used in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference
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
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
Java thread state
Java thread state  what is Static binding
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 class
Java Thread Class is a piece of the program execution Java has... It is created by extending the Thread class or implementing Runnable interface Java Thread Class Example public class thread1 extends Thread { @Override
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  What is the use of serializable
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  Can we have run() method directly without start() method in threads
Get Current Thread
; A Thread is the independent path of execution in a program. Many thread runs concurrently with a program. Some threads are Multithread, This thread refers to two or more thread running simultaneously within a program
thread - Java Beginners
thread  can i asko for programs in thread method that will allow user to input two separate names  Hi friend, For more information on Thread visit to : http://www.roseindia.net/java/thread/index.shtml Thanks
Java thread state
Java thread state  What is the difference between yielding and sleeping
Java thread state
Java thread state  Difference between sleep and suspend
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
Daemon thread - Java Beginners
information, visit the following link: http://www.roseindia.net/java/thread...Daemon thread  Hi, What is a daemon thread? Please provide me... thread which run in background. like garbadge collection thread. Thanks 
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 Sleep Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
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 
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

Ads