我可以访问 camunda 中计时器事件的值吗?

Can i access the value of the timer event in camunda?

由于我可以设置定时器事件的持续时间,我可以通过 java 代码访问它吗?或者作为 camunda 变量?

如果要访问XML中定义的属性,可以使用BPMN Model API。例如:

String processDefinitionId = ...
String timerEventId = ...

BpmnModelInstance bpmnModel = repositoryService.getBpmnModelInstance(processDefinitionId);
CatchEvent timerEvent = bpmnModel.getModelElementById(timerEventId);
TimerEventDefinition timerEventDefinition = 
  (TimerEventDefinition) timerEvent.getEventDefinitions().iterator().next();
TimeDuration duration = timerEventDefinition.getTimeDuration();
String configuredDuration = duration.getTextContent();

如果您想在运行时获取定时器下次触发的实际时间,您将必须查询相应的作业:

String processDefinitionId = ...
String timerEventId = ...
String processInstanceId = ...

Job timerJob = managementService.createJobQuery()
  .processDefinitionId(processDefinitionId)
  .activityId(activityId)
  .processInstanceId(processInstanceId)
  .singleResult();
Date firingDate = timerJob.getDueDate();

请注意,如果您查询的流程实例尚未到达计时器事件,则timerJob为空。