3 Replies Latest reply on Oct 27, 2016 8:57 AM by dmlloyd

    ExecutorService.newFixedThreadPool() - Possible thread leak?

    pacionet

      We have a web service REST which invokes a method which sends some mail, using multithreading, like this:

       

      [...]

       

      executor = Executors.newFixedThreadPool(10);

       

       

      list = new ArrayList<Future<Integer>>();

       

      for (int i = 0; i < recipients.length; i++) {

       

      email = new Email();

       

      [...]

       

      worker = new EmailService(email);

       

      future = executor.submit(worker);

       

      list.add(future);

      }

       

      executor.shutdown();

       

      while (!executor.isTerminated()) {}

      [...]

       

      When i monitor THREAD USAGE from Wildfly 10.1.0 console (STANDALONE SERVER -> MONITOR JVM ) I noticed that:

      THREAD USAGE->

           LIVE: increasing every time i invoke the method

           DAEMON: not increasing

      The statement executor.shutdown() seems not to kill the threads .  The thread simply send a mail and returns.

      Some hints?