04-10-2017 04:49 AM
My use case is this: I'm using the async executor. I have some async service tasks and I want to set the thread names for the threads that will be executing these tasks. I guess the same applies for script tasks - I want the thread that executes them to have a specific name. How can I achieve these things?
04-10-2017 04:06 PM
This would require that you overload the Job Executor service classes.
You can find the necessary classes under here:
Activiti/modules/activiti-engine/src/main/java/org/activiti/engine/impl/asyncexecutor at master · Ac...
Specifically you should look in AbstractAsyncJobExecutor.java
As for script tasks, it may be difficult to name the thread as sometimes the thread will be a servlet thread, sometimes it will be inherited from a previous job (sync continuation) and sometimes it will be picked up from the Job executor (async continuation).
Cheers,
Greg
04-10-2017 04:06 PM
This would require that you overload the Job Executor service classes.
You can find the necessary classes under here:
Activiti/modules/activiti-engine/src/main/java/org/activiti/engine/impl/asyncexecutor at master · Ac...
Specifically you should look in AbstractAsyncJobExecutor.java
As for script tasks, it may be difficult to name the thread as sometimes the thread will be a servlet thread, sometimes it will be inherited from a previous job (sync continuation) and sometimes it will be picked up from the Job executor (async continuation).
Cheers,
Greg
04-12-2017 04:52 AM
Thanks for the response! This is what I did:
AbstractAsyncJobExecutor asyncExecutor = new DefaultAsyncJobExecutor();
asyncExecutor.setExecuteAsyncRunnableFactory(MyExecuteAsyncRunnable::new);
processEngineConfiguration.setAsyncExecutor(asyncExecutor);
...
class MyExecuteAsyncRunnable extends ExecuteAsyncRunnable {
public MyExecuteAsyncRunnable(JobEntity job, CommandExecutor commandExecutor) {
super(job, commandExecutor);
}
@Override
public void run() {
Thread.currentThread().setName("asd");
super.run();
}
}
It seems to work correctly - does it look fine though? I don't like that I've hardcoded setting the async executor to be a DefaultAsyncJobExecutor but unfortunately processEngineConfiguration.getAsyncExecutor() returns null. Also, I'm extending the ExecuteAsyncRunnable class while there are others that I could extend - e.g. TenantAwareExecuteAsyncRunnable. Is that also correct? Is there a better way of doing all of those things?
As for the script tasks - you have no ideas how to make sure that all script tasks are executed in a specific thread?
Thanks again!
Explore our Alfresco products with the links below. Use labels to filter content by product module.