Tutorial Addendum On Java - Cilia Groups

strategygamesios android appcolt appcolt
 31 December 18:00   

    



    



    

Output:

    

 

    

ThreadGroup name = system

    

Has ancestor cilia accumulation = false

    

# of alive accoutrement = 6

    

Cilia name = Advertence Handler

    

Cilia name = Finalizer

    

Cilia name = Arresting Dispatcher

    

Cilia name = CompileThread0

    

# of alive sub cilia groups = 1

    

ThreadGroup name = main

    

Has ancestor cilia accumulation = true

    

# of alive accoutrement = 2

    

Cilia name = main

    

# of alive sub cilia groups = 0

    

java.lang.ThreadGroup

    

Thread

    

Thread

    

Thread

    

Thread

    

java.lang.ThreadGroup

    

Thread

    

Thread

    



    



    

Note that:

    



        

  • There are 4 Cilia altar in the "system" cilia group. I accept no abstraction

        

    what they are for.

        



  •     

  • The "main" cilia accumulation contains 2 Cilia objects. But the enumerate() method

        

    copies alone one cilia item - the "main" thread.

        



  •     

  • However the list() adjustment is accurately advertisement 2 Cilia objects, called

        

    "main" and "Thread-0".

        



  •     

  • What is the purpose of "Thread-0" thread? How to get a advertence of this thread?

        



  •     



    



    

Grouping Threads

    



    

The next program shows how to add added accoutrement and cilia groups to the ThreadGroup

    

tree:

    

 

    

/**

    

* GroupingThreads.java

    

* Absorb (c) 2003 by Dr. Yang

    

*/

    

class GroupingThreads {

    

accessible changeless abandoned main(String args) {

    

Cilia t = new AThread();

    

t.setName("AThread 1");

    

t = new AThread();

    

t.setName("AThread 2");

    

t.start();

    

t.interrupt();

    

t = new AThread();

    

t.setName("AThread 3");

    

t.start();

    

ThreadGroup g = new ThreadGroup("Group X");

    

t = new BThread(g, "BThread 4");

    

t = new BThread(g, "BThread 5");

    

t.start();

    

t = new BThread(g, "BThread 6");

    

t.start();

    

g.interrupt();

    

g = new ThreadGroup("Group Y");

    

t = new BThread(g, "BThread 7");

    

t.start();

    

t = new BThread(g, "BThread 8");

    

t.start();

    

g.interrupt();

    

try {Thread.sleep(1000);}

    

bolt (InterruptedException e) {}

    

g.destroy();

    

printInfo();

    

}

    

accessible changeless abandoned printInfo() {

    

Cilia t = Thread.currentThread();

    

ThreadGroup g = t.getThreadGroup();

    

g = g.getParent();

    

printInfo(g,"");

    

g.list();

    

}

    

accessible changeless abandoned printInfo(ThreadGroup g, Cord p) {

    

System.out.println(p+"ThreadGroup name = "+g.getName());

    

System.out.println(p+" Has ancestor cilia accumulation = "

    

+(g.getParent()!=null));

    

int n = g.activeCount();

    

System.out.println(p+" # of alive accoutrement = "+n);

    

Thread l = new Thread;

    

n = g.enumerate(l, false);

    

for (int i=0; i<n; i++) {

    

System.out.println(p+" Cilia name = "+l.getName());

    

}

    

n = g.activeGroupCount();

    

System.out.println(p+" # of alive sub cilia groups = "+n);

    

ThreadGroup s = new ThreadGroup;

    

n = g.enumerate(s, false);

    

for (int i=0; i<n; i++) {

    

printInfo(s," "+p);

    

}

    

}

    

changeless chic AThread extends Cilia {

    

accessible abandoned run() {

    

System.out.println("Running "+getName());

    

try {

    

sleep(1000*60*60);

    

} bolt (InterruptedException e) {

    

}

    

System.out.println("Ending "+getName());

    

}

    

}

    

changeless chic BThread extends Cilia {

    

accessible BThread(ThreadGroup g, Cord n) {

    

super(g,n);

    

}

    

accessible abandoned run() {

    

System.out.println("Running "+getName());

    

try {

    

sleep(1000*60*60);

    

} bolt (InterruptedException e) {

    

}

    

System.out.println("Ending "+getName());

    

}

    

}

    

}

    



    



    



    

 


Tags: active, system, class, groups, sleep, start, parent, group, catch, public, string, false

 thread, system, threadgroup, bthread, println, group, athread, getname, start, public, groups, active, printinfo, static, threads, interruptedexception, catch, parent, enumerate, sleep, interrupt, string, reference, setname, objects, class, false, , system out, thread name, thread groups, new bthread, thread group, threadgroup name, system thread, new threadgroup, setname athread, active threads, catch interruptedexception, parent thread, new athread, static void, active sub, name main, main thread, thread objects, public static, sub thread, public static void, parent thread group, sub thread groups, println ending getname, static void printinfo, println running getname, new threadgroup group, lang threadgroup name, threadgroup name system, threadgroup name main, java thread groups,

Share Tutorial Addendum On Java - Cilia Groups:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  java