-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.1.7
-
generic
-
generic
Name: dbT83986 Date: 02/15/99
According to the Spec's at the URL below. When a new Thread is started and
ThreadGroup is not specified. Then the Thread should belong to the Parent's Thread Group.
http://java.sun.com/docs/books/jls/html/javalang.doc18.html#2658
This is not true in
JDK1.1.6, JDK1.1.7, JDK1.1.7A, JDK1.2 RC1
Steps to recreate
1. compile Applet1.java
2. Set Empty CLASSPATH
3. use appletviewer to view Applet1.html
The cause of the problem is in Thread.java. If parameter ThreadGroup g is null
Then we should *ALWAYS* use parent.getThreadGroup() as the ThreadGroup for
this thread, irrespective of SecurityManager is set or not.
private void init(ThreadGroup g, Runnable target, String name){
Thread parent = currentThread();
if (g == null) {
/* Determine if it's an applet or not */
SecurityManager security = System.getSecurityManager();
/* If there is a security manager, ask the security manager
what to do. */
if (security != null) {
g = security.getThreadGroup();
}
/* If the security doesn't have a strong opinion of the matter
use the parent thread group. */
if (g == null) {
g = parent.getThreadGroup();
}
}
/* checkAccess regardless of whether or not threadgroup is
explicitly passed in. */
g.checkAccess();
>>>> this.group = g;
this.daemon = parent.isDaemon();
this.priority = parent.getPriority();
this.name = name.toCharArray();
this.target = target;
setPriority(priority);
g.add(this);
}
Here's the source
------------------Applet1.java-------------------
import java.awt.*;
import java.applet.*;
import java.lang.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
ThreadGroup group = new ThreadGroup("Group 1");
ThreadA threadA = new ThreadA();
new Thread(group,threadA).start();
}
}
class ThreadA implements Runnable {
public void run(){
System.out.println("Thread Group for ThreadA : " + Thread.currentThread().getThreadGroup());
ThreadB threadB = new ThreadB();
new Thread(threadB).start();
}
}
class ThreadB implements Runnable {
public void run(){
System.out.println("Thread Group for ThreadB : " + Thread.currentThread().getThreadGroup());
}
}
----------------------Applet1.html---------------
<HTML>
<HEAD>
<TITLE>Autogenerated HTML</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Applet1.class" WIDTH=430 HEIGHT=270></APPLET>
</BODY>
</HTML>
--------------------------------------------------
-- dims
###@###.###
(Review ID: 42061)
======================================================================
- relates to
-
JDK-4229558 (thread) ThreadGroup.activeCount vs ThreadGroup.enumerate on 1.1 vs 1.2
- Closed