Tutorial Addendum On Java - Cilia Groups

strategygamesios android appcolt appcolt
 31 December 18:00   

    



    



    

Output:

    

 

    

Running AThread 2

    

Ending AThread 2

    

Running AThread 3

    

Running BThread 5

    

Ending BThread 5

    

Running BThread 6

    

Ending BThread 6

    

Running BThread 7

    

Ending BThread 7

    

Running BThread 8

    

Ending BThread 8

    

ThreadGroup name = system

    

Has ancestor cilia accumulation = false

    

# of alive accoutrement = 9

    

Cilia name = Advertence Handler

    

Cilia name = Finalizer

    

Cilia name = Arresting Dispatcher

    

Cilia name = CompileThread0

    

# of alive sub cilia groups = 2

    

ThreadGroup name = main

    

Has ancestor cilia accumulation = true

    

# of alive accoutrement = 5

    

Cilia name = main

    

Cilia name = AThread 3

    

# of alive sub cilia groups = 1

    

ThreadGroup name = Accumulation X

    

Has ancestor cilia accumulation = true

    

# of alive accoutrement = 1

    

# of alive sub cilia groups = 0

    

java.lang.ThreadGroup

    

Thread

    

Thread

    

Thread

    

Thread

    

java.lang.ThreadGroup

    

Thread

    

Thread

    

Thread

    

Thread

    

java.lang.ThreadGroup

    

Thread

    



    



    

Note that:

    



        

  • As expected, new cilia groups were added to the "main" cilia accumulation by default.

        



  •     

  • As expected, new accoutrement are were added to the "main" cilia accumulation by default,

        

    if they were created after a cilia group.

        



  •     

  • Thread "AThread 1" was never started. It was appear by the list() method,

        

    but not included in the enumerate() method.

        



  •     

  • Based on the antecedent note, we can account the amount of unstarted accoutrement in

        

    thread accumulation by activeCount()-enumerate(Thread l, true).

        



  •     

  • Thread accumulation "Group Y" was destroyed by the destroy() method, if it became

        

    empty.

        



  •     



    



    

Memory Aperture With Unstarted Threads

    



    

There was a bug opened in 2001 for JDK 1.3 blue-blooded "Unstarted Cilia causes anamnesis leak"

    

See

    

http://developer.java.sun.com/developer/bugParade/bugs/4410846.html for details.

    



    

The bug address included the follwing program to appearance the anamnesis leak:

    

 

    

public chic ThreadTest {

    

accessible changeless abandoned main(String args) {

    

while (true) {

    

try {

    

Cilia t = new Thread();

    

// alpha cilia for anamnesis aperture workaround

    

// t.start();

    

t = null;

    

System.gc();

    

Thread.sleep(500);

    

} bolt (InterruptedException ie) {

    

ie.printStackTrace();

    

}

    

}

    

}

    

}

    



    



    

I ran this program on my J2SDK 1.4.1 system. As predicted, the anamnesis acceptance of the

    

JVM went up boring at a amount of about 4K per 15 seconds.

    



    

As I mentioned in antecedent sections, Cilia item created after a specific

    

thread accumulation will be added into the "main" group. So

    

in the ThreadTest program included in the bug report, all the accoutrement created

    

will be added in the "main" group, and will break there until they are started

    

and ended. If we accumulate creating new threads, the amount of accoutrement in the "main"

    

group will grow, and anamnesis acceptance will aswell grow.

    



    

But in my opinion, this is not absolutely a bug. JDK is advised to adapt all

    

Thread and ThreadGroup altar in a individual cilia accumulation tree. Appliance programs

    

are affected to use this structure, and haveto chase the rules.

    



    

However, this advised affection is alarming if not acclimated properly, as approved

    

by the bug report. It could be a accident for any server blazon application, if new threads

    

are created for new affiliation requests and the start() calls are not accomplished for

    

some reason.

    



    

One advantage to break this problem is to:

    



        

  • At the Cilia item conception time, add it to the cilia accumulation with a WeakReference.

        



  •     

  • At alpha time (when start() is called), change the WeakReference to a approved reference.

        



  •     



    



    

A brace of addendum on this option:

    



        

  • The anemic advertence for an unstarted cilia will acquiesce the debris beneficiary to abolish

        

    the thread, if there is no added approved references to this cilia in the application.

        



  •     

  • Replacing the anemic advertence by a approved advertence if a cilia is started will

        

    prevent the debris beneficiary to abolish this active thread, even if there is no added

        

    regular advertence to this cilia in the application.

        



  •     

  • The accomplishing of this advantage could be two separate collections of accoutrement in

        

    a cilia group: one for unstarted accoutrement with anemic references, and the additional for started

        

    threads with approved references.

        



  •     



    



    

Without any advice from JDK, award a simple workaround to anticipate this from the

    

application ancillary is not easy.

    



    

However, you can put a argumentation in your appliance to watch the amount of unstarted

    

threads. If this amount is growing, you understand that about in your application

    

threads are created after the start() calls. Actuality is the cipher to account the

    

number of unstarted threads:

    

 

    

ThreadGroup g = Thread.currentThread().getThreadGroup();

    

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

    

Thread l = new Thread];

    

int unstartedThreadCount = g.activeCount() - g.enumerate(l,true):

    



    



    



    

 


Tags: added, active, program, system, application, created, groups, report, included, memory, start, method, parent, group, references, option, notes

 thread, group, threads, bthread, system, reference, unstarted, threadgroup, athread, memory, application, start, active, groups, regular, added, created, maxpri, option, parent, references, notes, report, enumerate, method, activecount, included, program, , thread group, thread groups, thread name, main thread, threadgroup name, unstarted threads, memory leak, new thread, created without, main group, regular reference, thread athread, system thread, sub thread, active sub, name main, parent thread, lang threadgroup, active threads, lang threadgroup name, sub thread groups, parent thread group, java lang threadgroup, main thread group, main thread athread, thread group true, threadgroup name main, java thread groups, threadgroup name group,

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