Hello Oliver,
The SLA of a job, including the execution policy, is only evaluated on the server side and does not provide the ability to modify the chosen node's number of threads. The execution policy only serves to filter the nodes for which a job is eligible.
Thus, you need another way to implement your requirements. A good solution would be to use a
node life cycle listener whose jobStarting() notification method would enforce the desired number of threads via the
node management APIs, using a local connection to the node JMX server.
As an example, here is a very simple implementation:
public class TimeSensitiveNodeListener extends NodeLifeCycleListenerAdapter {
@Override
public void jobStarting(NodeLifeCycleEvent event) {
Calendar now = new GregorianCalendar();
now.setTime(new Date());
int hour = now.get(Calendar.HOUR_OF_DAY);
int nbCores = Runtime.getRuntime().availableProcessors();
try (JMXNodeConnectionWrapper jmx = getJmxConnection()) {
// during business hours, use only one core
if ((hour < 9) || (hour > 18)) jmx.updateThreadPoolSize(1);
// during off hours, use all available cores
else jmx.updateThreadPoolSize(nbCores);
} catch(Exception e) {
e.printStackTrace();
}
}
// get a connection to the node's MBean server
private JMXNodeConnectionWrapper getJmxConnection() {
// local connection: no network involved, it's much faster
JMXNodeConnectionWrapper jmx = new JMXNodeConnectionWrapper();
jmx.connect();
return jmx;
}
}
You could eventually make this more sophisticated by having the actual schedule for business hours set as
job metadata, or any means you see fit ... the possibilities are without limit.
I hope this helps.
Sincerely,
-Laurent