1 Reply Latest reply: May 23, 2012 5:07 AM by rukbat RSS

    How to Shutdown my own Executor under Security Manager

    937555
      I have my Batch Application Program, in which I am using ThreadPoolExecutor in my Batch Application Program. So as soon as it hits the-

      executorService.shutdown();

      line in my Batch Application program, I always get this below error in my Batch Application Program. And I am not able to ShutDown my own Executor Service. Can anyone suggest me how should I overcome this error.

      causedByException=java.security.AccessControlException : Access denied (java.lang.RuntimePermission modifyThread)

      How can I shut down my own ExecutorService under SecurityManager.

      I am using Windows7 and Java6-IBM(java6-ibm-sr4ifx3-2009-06-22).

      I am trying to shut down like this-

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

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


                     // wait for termination
                     service.shutdown();
                     try {
                          if (!service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS)) {
                               service.shutdownNow();
                          }
                     } catch (final InterruptedException pCaught) {
                          service.shutdownNow();
                          Thread.currentThread().interrupt();
                     }