I have a job that takes too long time in Java. So I want to divide this job into threads and run them. After the threads finishes their jobs, returns to ...
OK, here's how you do it: /* * For testing purposes */ ThreadGroup tg = new ThreadGroup( "MyThreadGroup" ); Thread subThread = new Thread( tg, "New Thread - Inactive" ); try { /* * GETTING THREADS - PROBABLY BETTER TO GET IT BY USING * getDeclaredFields() AND LOOPING TILL GET ONE OF TYPE * Thread[] SINCE A FUTURE VERSION MIGHT CHANGE ...
i advice a thorough reading of any "java for dummies" or equivalent before posting. i don't see there is any Java tutorial forum available. Please check and post accordingly. any group is used to group things together for easy reference. This able to decouple the system. Imagine, you have a couple of loading job (IO operations) performed using Java threads. all ...
Hi Anthony, I dont know the answer to your question, but I have a suggestion. ThreadGroup.enumerate will give you a list of the active threads. class Test { public static void main(String[] args) { ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent()!=null) { tg=tg.getParent(); } // int count = tg.activeCount(); Thread[] t = new Thread[count]; System.out.println(count); // just curious // int count2 = ...
A question about threadgroup's activeCount and enumerate. We are looking at the number of threads in our Websphere application server (running on as400). If we look at the number of the recurvisely enumrated threads from the root threadgroup, it is constantly around the same figure of 150 active threads. However if we look at the activeCount, it rises every day with ...
While that loop is spinning (which is a BAD idea to do by the way, so please feel free to smack the developer of that CPU-burning code upside the head with a dead mackerel!), the threads in that thread group are doing their thing and finishing their work, thus making the activeCount() return different values until finally all the threads are ...
Whenever createAThread() method is called, a new thread is spawned. I want all the newly created threads (i.e. those that are spawned by createAThread() method) to belong to the same thread group so that I can, at any point of time, find out how many threads are active. I do not find a way to add these thread to a thread ...
example: public class OneThread extends Thread { public boolean state = true; public OneThread() { } public void run() { while( state != false ) { System.out.println("Running"); wait(2000); } } public void ThreadStop() { state = false; } } ThreadGroup thg = new ThreadGroup("etc"); OneThread one = OneThread(thg); one.start; This is correct? if I see you write for me. Richard