|
|
|
Re: How to block a specific Job [message #1816567 is a reply to message #1816561] |
Thu, 31 October 2019 12:33 |
Matthias Villiger Messages: 235 Registered: September 2011 |
Senior Member |
|
|
Hi Luis
What you describe should be possible using BlockingConditions. The job must call waitFor() to get the permit to run. What did not work with this solution?
Anyway, this implementation has the disadvantage that the thread waiting in the blocking condition is wasted. This thread from the pool could be used for other tasks during the waiting time if it would not have been blocked in the condition. But while it is blocked the pool cannot reassign any other work to the tread because from the pools perspective this thread is in use. Hence the pool would have to create a new thread for the work. And creating threads is a resource intensive task (that's why thread pools are used).
So, if you have a thread that performs any task and must wait at a certain point until a condition is met and continues the task afterwards, a BlockingCondition is fine.
In cases in which the task must not be performed at all (e.g. skip the execution) it would be better to find another solution.
Depending on the type of execution trigger (single or recurring) a solution could be to cancel the job and re-schedule as soon as needed again.
Or the task has an internal flag indicating if it should run or not and then at the start of the task immediately returning if false.
Hope this helps
Mat
[Updated on: Thu, 31 October 2019 12:35] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05289 seconds