3

I assume DefaultAsyncJobExecutor is the class which gets picked up by default as an implementation of AsyncExecutor interface (not sure if this assumption is right or not)

So basically I want to modify the default time-out duration of an asynchronous job, the default time-out duration is 5 minutes, which is the value of two variables:

timerLockTimeInMillis, asyncJobLockTimeInMillis in AbstractAsyncExecutor.java**

I tried to change both values with respective setter methods and tried to directly modify the value in the constructor of my custom implementation like this:

public class AsyncExecutorConfigImpl extends DefaultAsyncJobExecutor
{
    //    @Value( "${async.timeout.duration}" )
    private int customAsyncJobLockTimeInMillis = 10 * 60 * 1000;

    AsyncExecutorConfigImpl()
    {
        super();
        setTimerLockTimeInMillis( this.customAsyncJobLockTimeInMillis );
        setAsyncJobLockTimeInMillis( this.customAsyncJobLockTimeInMillis );
        super.timerLockTimeInMillis = this.customAsyncJobLockTimeInMillis;
        super.asyncJobLockTimeInMillis = this.customAsyncJobLockTimeInMillis;
    }
}

But the values remain same because time-out still happens after 5 minutes.

Initialisation is done via an API, like start-new-process-instance, in this APIfollowing code is there to start the process instance

->Start a workflow process instance asynchronously something like this (processInstanceName, processInstanceId)

ProcessInstance lProcessInstance = mRuntimeService.createProcessInstanceBuilder()
                                                              .processDefinitionId( lProcessDefinition.get().getId() )
                                                              .variables( processInstanceRequest.getVariables() )
                                                              .name( lProcessInstanceName )
                                                              .predefineProcessInstanceId( lProcessInstanceId )
                                                              .startAsync();

->Once this is done rest of the workflow involves service tasks and while one instance is executing, I guess the time-out occurs and instance gets restarted

-> Since, I have a listener configured I was able to see this in logs that start-event activity gets started after every 5 minutes

so for example: event-1 is the first event then this event is getting re-started after 5 minutes(duration is displayed in console logs)

Not sure, what I'm missing at this point, let me know if any other details required

Akki
  • 754
  • 7
  • 22
  • Remember that these are instance variables. Your implementation is correctly setting that field, but only for instances of your extended class. There is no real way to override it for all existing instances that you did not instantiate, i.e. if they are instantiated by the library – Michael Jan 16 '20 at 17:49
  • why declare a variable in an abstract class? Why not just doing something like CustomImplementation extends B and then CustomImplementation obj = new CustomImplementation(); obj.setCount(whatever you want here); ? – GJCode Jan 16 '20 at 17:52
  • @GJCode, please note that interface A, abstract class B and DefaultExecutedClass are part of jar, which was imported as a dependency, with my own custom classes, I'm trying to modify the default value of variable count in abstract class B – Akki Jan 16 '20 at 18:01
  • @Michael but there must be some way to override that value, so for example: this particular value can be anything like a timeout value for asynchronous job, so there must be a way to modify that, because not all real jobs complete within the default timeout – Akki Jan 16 '20 at 18:05
  • @user85421 I just tried setCount(int) in the constructor of CustomImplementation class, but it didn't work, count value which is used, it's still the default one – Akki Jan 16 '20 at 18:21
  • What does "it didn't work" mean? What happens when you run your code. What do you expect to happen instead? – Code-Apprentice Jan 16 '20 at 19:02
  • @user85421 I've added some more details in edit and my assumption is if DefaultExecutedClass is used, then my custom implementation which is extending it, should also get used – Akki Jan 17 '20 at 03:58
  • I did not create an instance of my implementation, not sure where would I need to create an instance of my custom implementation so that it should get picked up along with DefaultAsyncJobExecutor – Akki Jan 17 '20 at 07:34
  • @Akki I'd say that this question should be named how to change the 5 minute interval for Flowable. Not how to modify value in a compiled class. Can you share more information about how you initialise Flowable? Do you embed it, use Spring Boot, use the UI Applications? – Filip Jan 20 '20 at 22:26
  • @Filip thanks for the response, I've changed the question name along with more details on how I start a process Instance and how I log the time-out of 5 minute – Akki Jan 22 '20 at 05:50
  • One other piece that I need. How are you creating the process engine? Are you using the Spring Boot starters? – Filip Jan 22 '20 at 06:36
  • Yes, I'm using Spring boot, so all the services are autowired and available to be used – Akki Jan 22 '20 at 07:14

3 Answers3

1

if the jar file is not under your control you cannot change the default value of count because in the jar classes are compiled. You can only change the value inside of an object so you can super keyword:

class CustomImplementation extends DefaultExecutedClass{
  private int custom_count=1234;

  CustomImplementation(){
    super();
    super.count = this.custom_count;
  }

}

otherwise if you really need to change the original file you have to extract it from the jar

GJCode
  • 1,959
  • 3
  • 13
  • 30
  • I've added few more details as part of edit and after trying out what you suggested, the value is still unchanged – Akki Jan 17 '20 at 05:42
  • In the edit I see a totally different problem, maybe your issue is not related with setting a protected variable cause you are doing async jobs, so please provide your code and the references like the repository you have already provided – GJCode Jan 17 '20 at 08:27
  • I have an async job, which gets restarted after every 5 minutes, this link might provide more reference to real problem https://forum.flowable.org/t/how-to-change-the-5-minute-timeout-interval-for-a-async-job/2295/2 – Akki Jan 17 '20 at 08:58
  • 1
    please provide the code you have written so far, the error could be anywhere in your code (job configuration, code implementation and so on) explain what is the result you are obtaining and how you are obtaining it (like how you measure the time-out) and the right result that you should have instead. We cannot guess what is wrong with the details you have provided – GJCode Jan 17 '20 at 09:25
  • I've added more details in question, let me know if this clarifies a bit and there is not configuration for the jobs that need to be done, everything follows sequentially in the workflow by flowable – Akki Jan 17 '20 at 10:28
  • @GJCode Can you please help me to solve my question: https://stackoverflow.com/q/60925265/6097074 – ankit Mar 30 '20 at 09:08
1

When you are using the Flowable Spring Boot starters. Then the SpringAsyncExecutor is used, this uses the TaskExecutor from Spring. It's is provided as a bean. In order to change it's values you can use properties.

e.g.

flowable.process.async.executor.timer-lock-time-in-millis=600000
flowable.process.async.executor.async-job-lock-time-in-millis=600000

Note: Be careful when changing this. If your processes start is taking more than 5 minutes then this means that you have a transaction open for that duration of the time.

Filip
  • 19,269
  • 7
  • 51
  • 60
0

I have come across the same problem but could not find any solution. I am mentioning a workaround that has worked for me this far. The idea was to reduce the 'asyncJobLockTimeInMillis' time from 5 minutes to 30 seconds.

wfmEngine=ProcessEngines.getDefaultProcessEngine();
            
            ProcessEngineConfiguration engineConfig=wfmEngine.getProcessEngineConfiguration();
engineConfig.getAsyncExecutor().setAsyncJobLockTimeInMillis(30*1000);

My process activity execution times are much less than 30 seconds, so it has this far worked for me. I am not sure what will happen if the execution time is longer and the job gets unlocked during execution, perhaps another instance of executor would take up the job and try to execute it (I have not experimented on this).

This is certainly not a solution, I merely document this here as something that works out for me.

Ironluca
  • 3,402
  • 4
  • 25
  • 32