Where can I configure the thread pool behind the @Asynchronous calls in Java EE 6?

前端 未结 2 1403
后悔当初
后悔当初 2021-02-05 23:45

I recently learned that I can easily make any session bean method Asynchronous by simply adding the @Asynchronous annotation.

E.g.

@Asynch         


        
2条回答
  •  野的像风
    2021-02-06 00:20

    Even though the solution I found was tested only on Java EE 7/GlassFish 4.1, I think that it should work for GlassFish 3.x too.

    There's a JIRA entry on java.net where the different settings are listed. As Oracle is going to pull the plug on that site, I'll quote the relevant post here (formatting added):

    The configuration is in domain.xml, for example,

    
      
      
      
      
      
      
    
    

    All of the above properties are optional. Their default values:

    thread-core-pool-size: 16
    thread-max-pool-size: 32
    thread-queue-capacity: Integer.MAX_VALUE
    thread-keep-alive-seconds: 60
    allow-core-thread-timeout: false
    prestart-all-core-threads: false
    

    Via that thread, I also found a blog post that explains how the core and max pool size work. Quote of the important point:

    In the past SUN declared correctly: "That is exactly how it is supposed to behave. First the threads grow to coreSize, then the queue is used, then if the queue fills up then the number of threads expands from coreSize to maxSize. Hence if you use an unbounded queue the last part never happens. This is all described in the documentation. If you want an unbounded queue but more threads then increase the core size. Otherwise consider whether a bounded queue is more suitable to your needs."

提交回复
热议问题