9 Replies Latest reply: Jan 10, 2012 9:35 PM by jtahlborn RSS

    pool # and thread #

    Johnny_hunter
      hello all:

      My understanding about APIs such as Executors#newCachedThreadPool and Executors#newFixedThreadPool is that they have a thread pool and various or fixed number of threads. The source code shows that they internally call ThreadPoolExecutor, whose parameters, corePoolSize or maxPoolSize, IMO, also refer to the number of threads.

      However, when I log the default thread name when using these APIs, I see some format like pool-1-thread-202, pool-3-thread-1, which apprear to me there are multiple pools.

      Any clarifications?

      Thanks,
      John
        • 1. Re: pool # and thread #
          jtahlborn
          yes, each executor is a single pool. the multiple pool numbers indicate that you (or the jvm jre) have created multiple executor instances.

          Edited by: jtahlborn on Jan 10, 2012 10:39 PM
          • 2. Re: pool # and thread #
            Johnny_hunter
            thanks Jahlborn. I didn't create multile executor instances explicitly - under what circurmstances that the JVM feel needs to create multiple executor instances?
            • 3. Re: pool # and thread #
              jtahlborn
              Johnny_hunter wrote:
              thanks Jahlborn. I didn't create multile executor instances explicitly - under what circurmstances that the JVM feel needs to create multiple executor instances?
              for whatever it needs a thread-pool (likely candidates are more significant frameworks like webservers, etc). if you create stack dump of your application, you should be able to see what all the threads are doing. additionally, if you attach a memory profile to your application, you should probably be able to figure out what classes own what thread pools. this should enable you to determine where the other thread pools are getting instantiated.

              Edited by: jtahlborn on Jan 9, 2012 11:23 AM
              • 4. Re: pool # and thread #
                EJP
                under what circurmstances that the JVM feel needs to create multiple executor instances?
                Under no circumstances. The JVM doesn't create executor instances at all unless the application does so, or one of its component libraries.
                • 5. Re: pool # and thread #
                  jtahlborn
                  EJP wrote:
                  under what circurmstances that the JVM feel needs to create multiple executor instances?
                  Under no circumstances. The JVM doesn't create executor instances at all unless the application does so, or one of its component libraries.
                  i guess that kind of depends how you define "JVM". if you define it as the native code only, i guess that's true. If you include all the code included as part of the JRE, then that is not true.
                  • 6. Re: pool # and thread #
                    EJP
                    There's only one definition for JVM. The JVM is the thing that executes bytecode, as defined in the Java Virtual Machine Specification.
                    • 7. Re: pool # and thread #
                      jtahlborn
                      EJP wrote:
                      There's only one definition for JVM. The JVM is the thing that executes bytecode, as defined in the Java Virtual Machine Specification.
                      that's fine, but splitting that hair for the purpose of answering this question doesn't seem to add anything of use. The OP's comment says "JVM" but it's pretty clear his intent is to refer to the "JRE".
                      • 8. Re: pool # and thread #
                        EJP
                        The OP's comment says "JVM" but it's pretty clear his intent is to refer to the "JRE".
                        It was you that first said "JVM" here. It is pretty clear your intent was to refer to the "JRE". So I said so.
                        • 9. Re: pool # and thread #
                          jtahlborn
                          EJP wrote:
                          The OP's comment says "JVM" but it's pretty clear his intent is to refer to the "JRE".
                          It was you that first said "JVM" here. It is pretty clear your intent was to refer to the "JRE". So I said so.
                          Ah, so i did. Your supposed "clarification" seems more like it is arguing against my intent, not clarifying my usage of the term "jvm" to mean "jre".