Online Java Compiler By
JavaTpoint.com
public class JavaCheckAccessExp extends Thread { JavaCheckAccessExp(String threadname, ThreadGroup tg) { super(tg, threadname); start(); } public void run() { for (int i = 0; i < 2; i++) { try { Thread.sleep(10); } catch (InterruptedException ex) { System.out.println("Exception encounterted");} } System.out.println(Thread.currentThread().getName() + " finished executing"); } public static void main(String arg[]) throws InterruptedException, SecurityException { // creating a ThreadGroup ThreadGroup g1 = new ThreadGroup("Parent thread"); // creating a child ThreadGroup for parent ThreadGroup ThreadGroup g2 = new ThreadGroup(g1, "child thread"); // creating a thread JavaCheckAccessExp t1 = new JavaCheckAccessExp("Thread-1", g1); // creating another thread JavaCheckAccessExp t2 = new JavaCheckAccessExp("Thread-2", g1); // Check for access permission of current running thread g1.checkAccess(); System.out.println(g1.getName() + " has access"); g2.checkAccess(); System.out.println(g2.getName() + " has access"); } }
Output