Example usage for java.lang SecurityManager checkAccess

List of usage examples for java.lang SecurityManager checkAccess

Introduction

In this page you can find the example usage for java.lang SecurityManager checkAccess.

Prototype

public void checkAccess(ThreadGroup g) 

Source Link

Document

Throws a SecurityException if the calling thread is not allowed to modify the thread group argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    // check if accepting access for thread group is enabled
    sm.checkAccess(new ThreadGroup("example"));

    System.out.println("Allowed!");
}

From source file:org.apache.cassandra.concurrent.ContinuationsExecutor.java

/**
 * If there is a security manager, makes sure caller has permission to shut
 * down threads in general (see shutdownPerm). If this passes, additionally
 * makes sure the caller is allowed to interrupt each worker thread. This
 * might not be true even if first check passed, if the SecurityManager
 * treats some threads specially.//w w w.j a  va2s  .  c  o  m
 */
private void checkShutdownAccess() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(shutdownPerm);
        final ReentrantLock mainLock = this.mainLock;
        mainLock.lock();
        try {
            for (Worker w : workers)
                security.checkAccess(w.thread);
        } finally {
            mainLock.unlock();
        }
    }
}