In the documentation of the interrupt() method we have:
Throws:
SecurityException - if the current thread cannot modify this thread
The source code of the method is this:
public void interrupt() {
if (this != Thread.currentThread())
checkAccess(); //checking access
//The rest is ommited
}
The checkAccess
method, in turn is implemented as follows:
public final void checkAccess() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkAccess(this);
}
}
By default, as far as I got any thread is permitted to modify anyone else thread.
But is there a way to specify modifyThread
permission in the java.policy
file to allow a thread modify only itself?
In the java.policy
I could find the only grant{ ... }
section. Is there a way to deny such threads communications?