Query processInstance's startTime occur some mistakes

Halo, boys.
I want to query some active processInstances and tasks info. I found that these have same startTime.

flowable.cfg.xml

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="url" value=..... />
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="username" value=..... />
        <property name="password" value=..... />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="processEngineConfiguration" class="org.flowable.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="asyncExecutorActivate" value="false" />
        <property name="deploymentResources"
                  value="classpath*:META-INF/*.bpmn20.xml" />
    </bean>

    <bean id="processEngine" class="org.flowable.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>

    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

start process:

public void startAuditingProcessByProcessID(String processId) {
       runtimeService.startProcessInstanceByKey(processId);
    }

However ,

I found that using these code will work well. :tired_face:(each process (or task) startTime are diff )

processEngineConfiguration.getClock().setCurrentTime(null); 

any solution for this case? I didn’t add any clock to inject into processEngineConfiguration .

  • Project:

    Springboot 1.4.2+ flowable 6.4 + mysql 5.+

`

Thx a lot.

:persevere: anyone knows?

What do you mean by these have same startTime?

The default clock is a normal clock that returns new Date() on each invocation, so the start time between different processes should be different.

Are you doing this in tests or this happens on a deployed instance?

Cheers,
Filip

thanks for replying. In my case, I repackage flowable API in my service:

  1. When I call “Start” API, then it will call these code:
    public void startAuditingProcessByProcessID(String processId, Map value) {
//        cfg.getClock().setCurrentTime(null);
        if (value == null) {
            runtimeService.startProcessInstanceByKey(processId);
        } else {
            runtimeService.startProcessInstanceByKey(processId, value);
        }
    }
  1. then I will call function to see activiting proecss Instances like these:
public List<String> queryCandidateProcessByProcessId(String processId) {
        List<ProcessInstance> instanceList = runtimeService
                .createProcessInstanceQuery()
                .processDefinitionKey(processId)
                .list();
        List<String> result = new ArrayList();
        instanceList.sort((ProcessInstance o1, ProcessInstance o2) ->
                (o1.getStartTime().getTime() - o2.getStartTime().getTime() == 0 ? 0 :
                        (o1.getStartTime().getTime() - o2.getStartTime().getTime() < 0 ? 1 : -1)));
        Gson gson = new Gson();
        for (ProcessInstance instance : instanceList) {
            HashMap object = new HashMap();
            object.put("ProcessId", instance.getId());
            object.put("StartTime", instance.getStartTime());
            object.put("processInstanceId", instance.getProcessInstanceId());
            object.put("candidateTasks", queryCandidateTasksByProcessId(instance.getId()));
            result.add(gson.toJson(object));
        }
        return result;
    }
  1. I am sure that calling “Start” API in different time. But result is that:
[
    "{\"candidateTasks\":[\"{\\\"processInstanceId\\\":\\\"2501\\\",\\\"Id\\\":\\\"2510\\\"}\"],\"processInstanceId\":\"2501\",\"StartTime\":\"Oct 15, 2018 1:34:58 PM\",\"ProcessId\":\"2501\"}",
    "{\"candidateTasks\":[\"{\\\"processInstanceId\\\":\\\"2512\\\",\\\"Id\\\":\\\"2521\\\"}\"],\"processInstanceId\":\"2512\",\"StartTime\":\"Oct 15, 2018 1:34:58 PM\",\"ProcessId\":\"2512\"}",
    "{\"candidateTasks\":[\"{\\\"processInstanceId\\\":\\\"2523\\\",\\\"Id\\\":\\\"2532\\\"}\"],\"processInstanceId\":\"2523\",\"StartTime\":\"Oct 15, 2018 1:34:58 PM\",\"ProcessId\":\"2523\"}",
    "{\"candidateTasks\":[\"{\\\"processInstanceId\\\":\\\"2534\\\",\\\"Id\\\":\\\"2543\\\"}\"],\"processInstanceId\":\"2534\",\"StartTime\":\"Oct 15, 2018 1:34:58 PM\",\"ProcessId\":\"2534\"}",
    "{\"candidateTasks\":[\"{\\\"processInstanceId\\\":\\\"2545\\\",\\\"Id\\\":\\\"2554\\\"}\"],\"processInstanceId\":\"2545\",\"StartTime\":\"Oct 15, 2018 1:34:58 PM\",\"ProcessId\":\"2545\"}"
]

Recently I read flowable API

ProcessInstance’s startTime was set by

processInstanceExecution.setStartTime(CommandContextUtil.getProcessEngineConfiguration().getClock().getCurrentTime());

CurrentTime is:

.
real time is :

I know that I did not set “CURRENT_TIME” in DefaultClockImpl class anywhere.

Hi Denny.
Can you provide time in milliseconds for all process instances?

Martin

Here is start process response:
image

Here is the quering result:
image

@Denny from what you are showing us it looks like the current time of the clock is set manually. In your debugging CURRENT_TIME is not null.

Can you put a breakpoint in the DefaultClockImpl to figure out who calls setCurrentCalendar or setCurrentTime?

@filiphr thx for advise, I try to debug program. It can be show in following steps:

  1. SpringBoot config start:
calling:
ProcessEngineConfigurationImpl.initClock()   
to new a DefaultClockImpl() class;
  1. SpringProcessEngineConfigurator call initialiseCommonProperties()
SpringProcessEngineConfigurator.configure(....); 
SpringProcessEngineConfigurator.initialiseCommonProperties(...);
AbstractEngineConfigurator.initClock(....);
  1. ProcessEngineConfigurationImpl start configing:
    image
    and then
    image

Because step1 would return an instance GregorianCalendar, so that CURRENT_TIME will not be null.

In additon, I think I don’t set clock in anywhere by manually. the debugging stacks comes from springboot starting. Should I show more details about codes?( actually it’s just a demo now).

Can you debug the contents of this list and verify that startTime is the same for your started process instances or different? I have tested starting two processes in my java test project and startTime is different, as expected.

(Tested in a similar setup: flowable-spring-boot + java code + mysql database)

@inakihn
Instance[0]
image
Instance[8]
image

As we’re not able to reproduce, can you maybe share a simple example om Github that we can try it out?

@joram thanks for replying. Here is my demo.

Adding any issue about this demo is ok.:stuck_out_tongue_winking_eye: