Access Restriction Methods Multithreading

Access Restriction Methods

The ThreadGroup class itself does not impose any access restrictions, such as allowing threads from one group to inspect or modify threads in a different group. Rather the Thread and ThreadGroup classes cooperate with security managers (subclasses of the java.lang.SecurityManager class), which can impose access restrictions based on thread group membership.

The Thread and ThreadGroup class both have a method, checkAccess(), which calls the current security manager’s checkAccess() method. The security manager decides whether to allow the access based on the group membership of the threads involved. If access is not allowed, the checkAccess() method throws a SecurityException. Otherwise, checkAccess() simply returns.

The following is a list of ThreadGroup methods that call ThreadGroup’s checkAccess() before performing the action of the method. These are what are known as regulated accesses, that is, accesses that must be approved by the security manager before they can be completed.
1. ThreadGroup(ThreadGroup parent, String name)
2. setDaemon(boolean isDaemon)
3. setMaxPriority(int maxPriority)
4. stop()
5. suspend()
6. resume()
7. destroy()

This is a list of the methods in the Thread class that call checkAccess() before proceeding:
1. constructors that specify a thread group
2. stop()
3. suspend()
4. resume()
5. setPriority(int priority)
6. setName(String name)
7. setDaemon(boolean isDaemon)

We can define and implement our own access restrictions for thread groups by subclassing SecurityManager, overriding the appropriate methods, and installing it as the current security manager in our application.

Scroll to Top