0

HI the following code is used in a application

threadPool.shutdown();
        while (!threadPool.awaitTermination(10, TimeUnit.SECONDS)) {
            logger.info("Waiting for "
                    + (threadPool.getQueue().size() + threadPool
                            .getActiveCount()) + " jobs to complete.");
        }

when application is running it strucked in the loop

  • Waiting for 134 jobs to complete.
  • Waiting for 134 jobs to complete.
  • Waiting for 134 jobs to complete.

the above statement is coming continuosly,actually thread is performing update operation on database.will increasing the time to more than 10sec will help in this situation.any suggestion is helpful

siva
  • 5
  • 1
  • 6

1 Answers1

0

The documentation for ThreadPoolExecutor.shutdown() says:

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

Which means that your worker threads are responsible for shutting themselves down. You haven't provided the code for your workers, but I'm assuming they are performing a blocking operation that doesn't exit. A common approach to solving this is to have the workers routinely check in on a shared variable of some kind that is set just before the shutdown call. They are effectively told to stop whatever they're working on. An AtomicBoolean should do the trick.

Alex Taylor
  • 8,343
  • 4
  • 25
  • 40
  • actually worker's are performing some business operation.for few of the methods synchronized keyword is added .synchronized key word will lead to above situation? – siva Feb 17 '17 at 06:30