Java ThreadGroup.checkAccess()

Syntax

ThreadGroup.checkAccess() has the following syntax.

public final void checkAccess()

Example

In the following code shows how to use ThreadGroup.checkAccess() method.


/*w w  w  . ja va2s.  c  o  m*/
public class Main {

  public static void main(String[] args) {
    ThreadGroupDemo tg = new ThreadGroupDemo();
  }
}
class ThreadGroupDemo implements Runnable {
  public ThreadGroupDemo() {
    try {
      ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

      ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

      Thread t1 = new Thread(pGroup, this);
      System.out.println("Starting " + t1.getName());
      t1.start();

      Thread t2 = new Thread(cGroup, this);
      System.out.println("Starting " + t2.getName());
      t2.start();

      pGroup.checkAccess();
      System.out.println(pGroup.getName() + " has access");
      cGroup.checkAccess();
      System.out.println(cGroup.getName() + " has access");
    } catch (Exception ex) {
      System.out.println(ex.toString());
    }
  }

  // implements run()
  public void run() {
    System.out.println(Thread.currentThread().getName() + " finished executing");
  }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable