Microsoft SDK for Java

getThreadGroup

This method of the StandardSecurityManager Class determines the active thread group based on the current execution context.

Syntax

public ThreadGroup getThreadGroup();

Return Value

Returns the active thread group.

Remarks

This method overrides the java.lang.SecurityManager.getThreadGroup method. This method is called by the constructors of the java.lang.Thread class. Its purpose is to ensure that new threads are created in the thread group associated with the active code instead of in the thread group of the current thread.

To understand why this scheme is useful, consider the AWT event dispatch thread, which is a system thread that lives in the system thread group. If an applet creates a new thread while executing code on the dispatch thread, the new thread will be created in the thread group associated with that applet. If, instead, an attempt had been made to create the thread in the system thread group, it is likely that the attempt would have failed because the applet code probably does not have access rights to the system thread group.

The algorithm for determining the active thread group is as follows.

  1. Based on the classes associated with each stack frame on the call stack, locate the nearest SecurityClassLoader instance.

  2. If no SecurityClassLoader is found, the active thread group is simply the thread group of the current thread, as follows:
Thread.currentThread().getThreadGroup()
  1. Otherwise, a SecurityClassLoader instance was found. If the thread group of the current thread is a child of the thread group associated with that loader, return it. Otherwise, return the thread group associated with the loader.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.