English 中文(简体)
(java.lang.RuntimePermission reformation Thread) 拒绝访问(java.lang.RuntimePermission referation)
原标题:java.security.AccessControlException : Access denied (java.lang.RuntimePermission modifyThread)

我有我的批量应用程序, 在我的批量应用程序中使用 Thread Pool 执行程序。 所以一旦它击中...

executorService.shutdown();

在我的批次应用程序行中, 我总是在批次应用程序中有这个错误。 我无法关闭自己的执行器服务 。 任何人都可以建议我如何克服这个错误 。

Batch Execution Failed!
TaskResponse[exitCode=
   <ExitCode 
       type="User"
       code="30"
       msg="Unexpected error encounted"/>,
    causedByException=java.security.AccessControlException : Access denied (java.lang.RuntimePermission modifyThread)
]

java.security.AccessControlException: Access denied (java.lang.RuntimePermission modifyThread)
   at java.security.AccessController.checkPermission(AccessController.java:108)
   at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
   at java.util.concurrent.ThreadPoolExecutor.shutdown(ThreadPoolExecutor.java:1104)
   at com.host.task.Testing.CommandExecutor.runNextCommand(CommandExecutor.java:185)
   at com.host.task.Testing.PDSBatchTask.execute(PDSBatchTask.java:66)
   at com.host.nel.batch.runtime.Task.start(Task.java:234)
   at com.host.nel.batch.runtime.rt.TaskManager.__executeTask(TaskManager.java:138)
   at com.host.nel.batch.runtime.rt.TaskManager.executeTask(TaskManager.java:73)
   at com.host.nel.batch.runtime.rt.BatchManager.__executeTask(BatchManager.java:302)
   at com.host.nel.batch.runtime.rt.BatchManager.executeBatchApplication(BatchManager.java:126)
   at com.host.nel.batch.driver.BatchMain.main(BatchMain.java:95)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
   at java.lang.reflect.Method.invoke(Method.java:599)
   at com.host.nel.batch.testutils.TestBatchMain$1.run(TestBatchMain.java:50)
   at java.security.AccessController.doPrivileged(AccessController.java:251)
   at com.host.nel.batch.testutils.TestBatchMain.driver(TestBatchMain.java:37)
   at com.host.nel.batch.testutils.TestBatchMain.driver(TestBatchMain.java:21)
   at test.com.host.task.Testing.Driver.main(Driver.java:21)

Update- I tried doing this way, but still no luck-

// create thread pool with given size
            final ExecutorService service = Executors.newFixedThreadPool(10); 

            // queue some tasks
            for(int i = 0; i < 3 * 10; i++) {
                service.submit(new ThreadTask(i));
            }


            AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    // privileged code goes here, for example:
                    service.shutdown();
                    try {
                        if (!service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS)) {
                            service.shutdownNow();
                        }
                    } catch (final InterruptedException pCaught) {
                        service.shutdownNow();
                        Thread.currentThread().interrupt();
                    }

                    return null; // nothing to return
                }
            });
最佳回答

不要用安全管理器运行您的批量测试代码。 或者,授予您的代码修改Thread RuntimePermission 。

问题回答

您可以在 doprivileed 块中尝试关闭您的执行器

AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                // privileged code goes here, for example:
                executorService.shutdown();
                return null; // nothing to return
            }
        });




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签