1

我有一个例外如下:

2013-10-22 15:16:12 SEVERE Thread-247(247) AspectJExceptionCatcher java.lang.SecurityException: You can not modify this map
    at org.apache.harmony.security.fortress.SecurityUtils.putContext(SecurityUtils.java:78)
    at java.lang.Thread.create(Thread.java:499)
    at java.lang.Thread.<init>(Thread.java:205)
    at com.common.conn.ConnectTask.<init>(ConnectTask.java:80)
    at com.common.conn.CommuTask.<init>(CommuTask.java:43)
    at com.common.conn.ConnectionService$3.sendMsg(ConnectionService.java:144)
    at com.business.favorite.FavorManager.getFolderSong(FavorManager.java:243)
    at com.business.favorite.FavorManager$6.onResult(FavorManager.java:1465)
    at com.common.conn.CommuTask.handleData(CommuTask.java:237)
    at com.common.conn.CommuTask.run(CommuTask.java:209)

阅读 SecurityUtils.java 代码后,错误是由于线程已存在。而我的代码确实有这样的逻辑。CommnuTask 是一个线程,在其 run() 函数流中,它尝试创建另一个其类型的线程。为什么这是被禁止的?以及如何解决?非常感谢。

http://svn.apache.org/repos/asf/harmony/enhanced/java/branches/mrh/drlvm/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/security/fortress/SecurityUtils.java

public static void putContext(Thread thread, AccessControlContext context)
        throws SecurityException {
    if (thread == null) {
        throw new NullPointerException("thread can not be null");
    }
    synchronized (ACC_CACHE) {
        if (ACC_CACHE.containsKey(thread)) {
            throw new SecurityException("You can not modify this map.");
        }
        if (context == null) {
            // this only allowed once - for the very first thread.
            if (ACC_CACHE.containsValue(null)) {
                throw new Error("null context may be stored only once.");
            }
        }
        ACC_CACHE.put(thread, context);
    }
}
4

0 回答 0