Glassfish设置最大并发批处理作业数 [英] Glassfish set max number of concurrent Batch Jobs

查看:388
本文介绍了Glassfish设置最大并发批处理作业数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GlassFish允许您调整全局EJB池大小以及每个EJB的特定池大小。通过在 glassfish-ejb-jar.xml 下设置 max-pool-size ,我可以控制一个EJB可以并行使用。

 < glassfish-ejb-jar> 
< enterprise-beans>
< ejb>
< ejb-name> MyExpensiveEJB< / ejb-name>
< bean-pool>
< max-pool-size> 10< / max-pool-size>
< / bean-pool>
< / ejb>
< / enterprise-beans>
< / glassfish-ejb-jar>

我想知道Java EE Batch API是否可以做类似的事情。我想配置最大并行作业数(全局或特定作业),以便调用 BatchRuntime.getJobOperator()。start() 将作业执行排入指定的限制之后。



任何人都知道这是否可能?

解决方案

回答我自己的问题以供进一步参考。



问题



默认情况下,GlassFish批处理运行时使用 concurrent / __ defaultManagedExecutor 作为其执行程序服务。您可以通过以下方式检索其属性:

  ./ asadmin get resources.managed-executor-service.concurrent / \ 
__defaultManagedExecutorService。*

在我的环境中,我得到以下值:

 上下文信息= Classloade r,JNDI,Security,WorkArea 
context-info-enabled = true
core-pool-size = 0
deployment-order = 100
enabled = true
hung -after-seconds = 0
jndi-name = concurrent / __ defaultManagedExecutorService
keep-alive-seconds = 60
long-running-tasks = false
maximum-pool-size = 2147483647
object-type = system-all
task-queue-capacity = 2147483647
thread-lifetime-seconds = 0
thread-priority = 5

请注意, maximum-pool-size = 2147483647 ,这是一个无限的托管执行程序。

解决方案




  1. 创建您自己的 Managed Executor Service

      ./ asadmin create-managed-executor-service --maximumpoolsize = 20 \ 
    --taskqueuecapacity = 5000 --longrunningtasks = true concurrent / myJobExecutor

    这会将池限制为20个并发线程。如果所有线程当前都在使用中,执行程序服务将排队多达5000个任务,然后再拒绝新条目。

  2. --longrunningtasks = true )在我的环境中不起作用。这个标志很重要,它可以防止长时间运行的任务被挂起。我必须手动设置属性:

      ./ asadmin set resources.managed-executor-service.concurrent / \ 
    myJobExecutor.long-running-tasks = true


  3. 调整批处理运行时配置以使用你的新托管执行器服务(我还必须设置数据源):

      ./ asadmin set-batch-runtime-configuration --executorservicelookupname \ 
    concurrent / myJobExecutor --datasourcelookupname jdbc / __ TimerPool


  4. 消除你的工作,享受美好,理智和平行。

  5. 可以在中找到有关配置批处理运行时和配置托管执行程序服务的更多信息GlassFish管理指南


    GlassFish allows you to tune the global EJB pool size, as well as specific pool sizes per EJB. By setting the max-pool-size under glassfish-ejb-jar.xml I can control how many instances of a EJB can be used in parallel.

    <glassfish-ejb-jar>
        <enterprise-beans>
            <ejb>
                <ejb-name>MyExpensiveEJB</ejb-name>
                <bean-pool>
                   <max-pool-size>10</max-pool-size>
                </bean-pool>
            </ejb>
        </enterprise-beans>
    </glassfish-ejb-jar> 
    

    I wonder if something similar can be done with the Java EE Batch API. I would like to configure the max number of parallel jobs (either globally or to a specific job) so that calls to BatchRuntime.getJobOperator().start() enqueues job executions after a specified limit.

    Anyone knows if this is possible?

    解决方案

    Answering my own question for further reference.

    Problem

    By default GlassFish Batch Runtime uses concurrent/__defaultManagedExecutor as its executor service.

    You can retrieve its properties with:

    ./asadmin get resources.managed-executor-service.concurrent/\
    __defaultManagedExecutorService.*
    

    In my environment I get the following values:

    context-info=Classloader,JNDI,Security,WorkArea
    context-info-enabled=true
    core-pool-size=0
    deployment-order=100
    enabled=true
    hung-after-seconds=0
    jndi-name=concurrent/__defaultManagedExecutorService
    keep-alive-seconds=60
    long-running-tasks=false
    maximum-pool-size=2147483647
    object-type=system-all
    task-queue-capacity=2147483647
    thread-lifetime-seconds=0
    thread-priority=5
    

    Notice thatmaximum-pool-size=2147483647, this is a unlimited managed executor.

    Solution

    1. Create your own Managed Executor Service.

      ./asadmin create-managed-executor-service --maximumpoolsize=20 \
      --taskqueuecapacity=5000 --longrunningtasks=true concurrent/myJobExecutor
      

      This will limit the pool to 20 concurrent threads. If all threads are currently in use the executor service will queue up to 5000 tasks before rejecting new entries.

    2. Unfortunately the last option(--longrunningtasks=true) did not work in my environment. This flag is important, it prevents long running tasks to be hung. I had to set the property manually:

      ./asadmin set resources.managed-executor-service.concurrent/\
      myJobExecutor.long-running-tasks=true
      

    3. Tweak the batch runtime configuration to use your new Managed Exercutor Service (I had to set the datasource as well):

      ./asadmin set-batch-runtime-configuration --executorservicelookupname \   
      concurrent/myJobExecutor --datasourcelookupname jdbc/__TimerPool
      

    4. Fire your jobs and enjoy nice, sane, parallelism.


    You can find further information about Configuring the Batch Runtime and Configuring Managed Executor Services in the GlassFish Administration Guide

    这篇关于Glassfish设置最大并发批处理作业数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆