Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

java - JSR352 How to prevent same job to run twice?

I am using JBeret on WildFly.

Is there a way to prevent a Job from running twice at the same time?

I.e. a Job is scheduled to run every hour. If the Job runs longer than an hour, I dont want it to run twice at the same time, meaning the second instance should fail or otherwise reject to be started.

Is there a way do declare that kind of behavoir in the Batch xml files?

question from:https://stackoverflow.com/questions/65925038/jsr352-how-to-prevent-same-job-to-run-twice

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, I don't see any way to do that in job xml. Your application code can check if there is any running job executions for the same job name, and then decides to start a new execution or not. For scheduled executions, you can add such a check in the scheduled task to check, and if there is one, the task can just bail out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...