Introduction to Activiti Workflow Engine and Its Usage
This article explains the concept of workflow, introduces the open‑source Activiti engine that implements BPMN 2.0, describes its database schema, outlines the basic lifecycle of a workflow, and provides step‑by‑step guidance on creating, deploying, starting, and managing processes with Java and Spring.
Before explaining Activiti, we first look at what a workflow is.
Workflow is the automation of a business process, either partially or wholly, within a computer application environment, enabling predefined rules to automatically pass documents, information, or tasks among participants to achieve a business goal.
In my view, a workflow breaks a large business logic into segments and centrally controls their execution conditions, order, and communication, achieving decomposition and decoupling of business logic.
Activiti is an open‑source workflow engine that implements the BPMN 2.0 specification, allowing you to publish designed process definitions and schedule them via API.
BPMN (Business Process Model and Notation) defines the basic symbols for process diagrams and how they combine to form a Business Process Diagram.
Activiti 5.13 uses 23 tables to support the entire workflow framework, with MyBatis handling database operations. The tables are:
1) ACT_RE_*: repository tables storing static resources such as images and rules. 2) ACT_RU_*: runtime tables containing process instances, tasks, variables, asynchronous tasks, etc.; records are deleted after the process ends. 3) ACT_ID_*: identity tables holding user and group information. 4) ACT_HI_*: history tables storing historical process instances, variables, tasks, etc. 5) ACT_GE_*: generic tables, e.g., bytearray for binary data.
The basic workflow process is: define the process (outside the framework) → deploy the process definition → start a process instance (framework moves to task 1) → claim a group task → complete a personal task (framework moves to task 2) → repeat. Group tasks can be claimed by multiple users and must be claimed before they become personal tasks.
2. Activiti Usage
2.1 Create ProcessEngine
The ProcessEngine controls the entire workflow.
It can also be integrated with Spring; the applicationContext.xml configuration is shown in the following image.
2.2 Deploy Process Definition
A process is defined by the user through BPMN (XML) files, as illustrated by the BPMN diagram above.
The defined process must be deployed to Activiti before it can be used.
2.3 Start Process Instance
2.4 Handle Task
2.5 Other Operations
Through JavaBeans you can access fields such as: processInstance.getActivityId() – the current task name processDefinition.getDiagramResourceName() – the name of the diagram image in the definition file
2.6 Process Variables
Multiple tasks can communicate via process variables, which are stored as key‑value pairs in the act_ru_variable table; within the same process instance, setting a variable with an existing key overwrites the previous value.
Variables can also be referenced in process definitions using expressions like ${variableName}, which the engine resolves from act_ru_variable before executing the corresponding task.
There is an overloaded method for starting a process instance that also accepts a business key:
processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey, businessKey, variables);The businessKey is usually set to the primary key of a business table, making it easy to retrieve the latest business state when using Activiti.
2.7 Group Tasks
Group Task 1
Group Task 2
2.8 Exclusive Gateway
Setting branch conditions.
3. Some Usage Experience
1) Consider mapping each workflow task to a business segment and set taskDefinitionKey to the corresponding Struts action method for better reusability.
2) Two ways to query process definitions; the latter provides more detailed information:
repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult()and
(ProcessDefinitionEntity) repositoryService.getProcessDefinition(id).
© Copyright: Content sourced from the internet; original author retains rights. If any infringement is found, please notify us for removal.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
