rajesh kumar swain
java thread program
1 Answer(s)      a year and a month ago
Posted in : Java Interview Questions

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









Related Pages:
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
Thread
Thread  Write a Java program to create three theads. Each thread should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread....   Java Thread Example class ThreadExample{ static int
Thread
;Java throw and throws Whenever we want to force an exception then we use throw... a possible exception then we use throws keyword. Point to note here is that the Java... instead of try and catch exception handler. For instance in the above given program we
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
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
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
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
Thread
=" + i); } public static void main(string args[]) { A a = new A(); Thread t = new thread(a); t.start(); } } Is it possible to run above program with out...Thread  will this code work..? class A extends Thread { public
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
Main Thread and Child Thread
There are two types of threads in Java Progarm In Java there are Main and Child Threads used in Programming. Main thread is automatically created when program runs. Child Thread gets created by the main thread . Java Main
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
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
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
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 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 - Java Beginners
Java Thread  What is thread in Java? and how can i write a Java thread program?Thanks in advance!!  Hi friend,import javax.swing.*;import...(a); } private JPanel canvas;}class Ball extends Thread { public Ball(JPanel
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
Green Thread - Java Beginners
of Green Thread in java. Thanks in advance...  Hi friend Green threads... the years. This is simple program of thread public class ThreadExample... thread), but VM technology has advanced significantly since version 1.1 and any
Thread Priorities
;    In Java, thread scheduler can use the thread...; When a Java thread is created, it inherits its priority from the thread...("My Thread 2");   } }   Output of the Program:  
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link: Java Threads Thanks
Thread Priorities
;   In Java, thread scheduler can use the thread priorities... a Java thread is created, it inherits its priority from the thread... :Thread[My Thread 1,1,main] In this program two
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 Priorities
;    In Java, thread scheduler can use the thread...; When a Java thread is created, it inherits its priority from the thread... :Thread[My Thread 1,1,main]   In this program
Overview of Thread
with this program. Thread A thread is a lightweight process which exist within... within a program. Each thread has its own local variables, program counter... of a program. Threading concept is very important in Java through which we
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
Thread in java
A thread is a lightweight process which exist within a program and executed... Overview of Threads Threading in Java Thread Creation... with a single process. Thus a process that has only one thread is referred
Thread Creation
; In Java, an object of the Thread class can represent a thread. Thread.... The following program demonstrates a single thread creation extending ... RunThread.java C:\j2se6\thread>java RunThread Thread
java Thread
java Thread  what is purpose of Thread
Thread in java
Thread in java  which method will defined in thread class
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
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
related to multiple thread....!!!!
related to multiple thread....!!!!  Write a Java program, which creates a linklist for Employees info viz. EmpID, EmpName, EmpAge. All operations should be performed on the linklist, like; Create, Add, Delete, Update, Size
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
CREATE AND WRITE FILE THREAD JAVA
CREATE AND WRITE FILE THREAD JAVA  Hi guys I was wondering how can I make this program in java with threads. I need to create a file and write in it (i know how to do that) but by listening in some port all the data that is being
Thread priority in java
. Example : A program how to set or get priority of thread in java. class...Thread priority in java A thread is a part or entity of a  process... concurrently. In java each and every thread has priority , priority means which
how to control program/thread 's access authority - Security
how to control program/thread 's access authority£¿  how to control program/thread 's access authority like program can't change I/O and change...(){ String s = "This is thread " + ThreadCount++; Vector vec = new
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 Memory Usage in java - Java Beginners
://www.roseindia.net/java/thread/thread-creation.shtml   but,if I use G++ tools to compile a c++ program in a java thread, as:Runtime.getRuntime...Thread Memory Usage in java  how to get a thread's memory usage? Does
How to Explain different way of using thread?
how to using different thread in Java program........   Hi, There are different types Thread in Java program. Here is the explain how to using thread in Java Program
How to Explain different way of using thread?
How to Explain different way of using thread?  Hi, How to explain how to using different thread in Java program
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.