This method of the StandardSecurityManager Class determines the active thread group based on the current execution context.
public ThreadGroup getThreadGroup();
Returns the active thread group.
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.
Thread.currentThread().getThreadGroup()