-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
1.4.1, 5.0
-
generic, sparc
-
generic, solaris_8
Name: viR10068 Date: 03/20/2003
The TreadGroup.destroy() method does not destroy the non-active subgroup.
But the specification says:
"Destroys this thread group and all of its subgroups."
See the source and execution log for details.
Source:
----------------------- B.java ------------------------------
import java.io.PrintStream;
class Bt extends Thread {
B event;
Bt(Bg group, B event) {
super(group, group.groupName + ".activeThrd");
this.event = event;
}
public void run() {
event.run();
}
} // end class Bt
class Bg extends ThreadGroup {
String groupName;
Thread activeThrd;
B event;
void finish() throws InterruptedException {
activeThrd.join();
}
Bg(ThreadGroup parent, B event) {
super("Bg_");
this.event = event;
groupName = "Bg_";
activeThrd = new Bt(this, event);
activeThrd.start();
}
} // end class Bg
public class B {
boolean end = false;
public synchronized void run() {
while (!end) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
public synchronized void stopAll() {
end = true;
notifyAll();
}
public int run(String argv[], PrintStream out) {
Bg group = new Bg(Thread.currentThread().getThreadGroup(), this);
Bg cgroup = new Bg(group, this);
try {
stopAll();
group.finish();
cgroup.finish();
} catch (InterruptedException e) {
out.println("InterruptedException while joining child thread.");
return 2;
}
try {
group.destroy();
} catch (Throwable e) {
out.println("unexpected exception:" + e);
return 2;
}
if (!group.isDestroyed()) {
out.println("destroy() called but group !isDestroyed()");
return 2;
}
out.println("OK: destroy() called and 'group' isDestroyed()");
if (!cgroup.isDestroyed()) {
out.println("destroy() called but 'cgroup' !isDestroyed()");
return 2;
}
out.println("OK: destroy() called and 'cgroup' isDestroyed()");
return 0;
}
public static void main(String args[]) {
(new B()).run(args, System.out);
}
}
-------------------------------------------------------------
Execution log:
% /jdk1.5.0/solaris-sparc/bin/java -showversion B
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b02)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b02, mixed mode)
OK: destroy() called and 'group' isDestroyed()
destroy() called but 'cgroup' !isDestroyed()
% java -showversion B
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
OK: destroy() called and 'group' isDestroyed()
destroy() called but 'cgroup' !isDestroyed()
%
======================================================================
- relates to
-
JDK-4148460 (spec thread) ThreadGroup hierarchy destruction should be bottom up, not top down
- Closed