我有我的批处理应用程序,我在批处理应用程序中使用ThreadPoolExecutor。所以一旦它到达 -
executorService.shutdown();
在我的批处理应用程序中,我总是在我的批处理应用程序中得到以下错误。而且我无法关闭我自己的Executor服务。任何人都可以建议我如何克服这个错误。
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)
更新 - 我试过这样做,但仍然没有运气 -
// 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
}
});
答案 0 :(得分:1)
不要使用SecurityManager运行批处理测试代码。或者,为您的代码授予modifyThread RuntimePermission。
答案 1 :(得分:0)
您可以尝试在doPriviledged
块
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// privileged code goes here, for example:
executorService.shutdown();
return null; // nothing to return
}
});