Java Data Type Tutorial - Java Thread.checkAccess()








Syntax

Thread.checkAccess() has the following syntax.

public final void checkAccess()

Example

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

//  ww w. jav a 2  s .  com

public class Main {

   public static void main(String args[]){

      new ThreadClass("A");
      Thread t = Thread.currentThread();

      try {
         t.checkAccess();
         System.out.println("You have permission to modify");
      }
      catch(Exception e) {
         System.out.println(e);
      }
   }
}

class ThreadClass implements Runnable {

   Thread t;
   String str;

   ThreadClass(String str) {

      this.str = str;
      t = new Thread(this);
      // this will call run() function
      t.start();    
   }

   public void  run() {
      System.out.println("This is run() function");
   }
}

The code above generates the following result.