我有一个 grails 应用程序和一个在其上运行的quartz 作业。该作业包含类似于以下的代码。
class MyJob{
static triggers = {}
def printLog(msg){
String threadId = Thread.currentThread().getId()
String threadName = Thread.currentThread().getName()
log.info(threadId+" - "+threadName+" : "+msg)
}
def execute(context)
{
printLog("Before Sync");
synchronized(MyJob){
printLog("Inside Sync");
try{
printLog("Before sleep 20 minutes")
Thread.sleep(1200000)
printLog("After sleep")
}catch (Exception e){
log.error("Error while sleeping")
}
}
printLog("After Sync")
}
}
我已安排它每分钟触发一次作业
我可以在日志中看到一个线程正在获取同步块(synchronized block),然后其他作业开始堆积,等待线程完成,这正在按预期工作。
这里的问题是作业在 10 分钟后停止,此时它已经创建了 10 个线程。其中一个线程休眠了 20 分钟,其他 9 个线程正在等待第一个线程释放锁。为什么没有创造新的就业机会?
我在一些答案中看到我可以通过修改我的触发器部分来解决问题,如下所示
static triggers = {
simple repeatInterval: 100
}
我尝试了上述选项,但它仍然只显示 10 个职位。
从哪里获取默认配置 10 ? 我如何修改该值以无限执行?
我对 grails 和quartz 很陌生,所以我不知道发生了什么。
最佳答案
我认为 Grails 插件在捆绑的quartz.properties 文件中将 threadCount 设置为 10,假设您使用的是 Grails 3,您可以像这样在 application.yml 中覆盖:
quartz:
threadPool:
threadCount: 25
Grails 2 - application.groovy
quartz {
props {
threadPool.threadCount = 100
}
}
关于grails - Quartz grail 插件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50150806/