【发布时间】:2015-09-27 04:57:31
【问题描述】:
在interrupt() 方法的文档中,我们有:
Throws:
SecurityException - if the current thread cannot modify this thread
方法的source code是这样的:
public void interrupt() {
if (this != Thread.currentThread())
checkAccess(); //checking access
//The rest is ommited
}
checkAccess方法,依次实现如下:
public final void checkAccess() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkAccess(this);
}
}
默认情况下,据我所知,任何线程都允许修改其他任何线程。
但是有没有办法在java.policy 文件中指定modifyThread 权限以允许线程只修改自己?
在java.policy 中,我可以找到唯一的grant{ ... } 部分。有没有办法拒绝这样的线程通信?
【问题讨论】:
-
如何修改自身?唯一相关的操作是
interrupt(), setName(),和setPriority()。这是您担心的其中之一吗?如果是,为什么? -
@VenkataRaju 他知道,他在询问细粒度权限(不存在)。
-
@EJP 我已经知道了。
标签: java multithreading