Introduction
The Cadence Java SDK is the official client library for building workflows and activities in Java and other JVM languages. It provides annotation-based workflow definitions, Spring Boot integration, and comprehensive tooling for enterprise applications.GitHub Repository
Official Cadence Java Client SDK - Star and contribute on GitHub
Installation
Prerequisites
- Java 8 or higher (Java 11+ recommended)
- Maven 3.6+ or Gradle 6.0+
- Cadence server running (local or remote)
Maven Setup
Add the Cadence Java client dependency to yourpom.xml:
pom.xml
Gradle Setup
Add the dependency to yourbuild.gradle:
Quick Start
1. Define a Workflow Interface
Workflow interfaces define the contract for workflow execution:2. Implement the Workflow
Workflow implementations must be deterministic:3. Define Activity Interface
Activities perform non-deterministic operations:4. Implement Activities
Activity implementations can call external services:5. Configure and Start Worker
Workers poll for and execute workflows and activities:6. Execute Workflow
Start workflow execution from your application:Advanced Patterns
Child Workflows
Compose complex workflows from simpler ones:Saga Pattern
Implement distributed transactions with compensation:Signals and Queries
- Signal Handler
- Query Handler
Retry Policies
Configure automatic retries for activities:Spring Boot Integration
Spring Configuration
Spring Worker Component
Testing
Unit Testing Workflows
Sample Repository
Cadence Java Samples
Enterprise examples including:
- Spring Boot integration
- Saga pattern implementation
- Complex orchestration scenarios
- Testing strategies
- Production configurations
Best Practices
Workflow Implementation
Workflow Implementation
- Keep workflow code deterministic
- Use
Workflow.getVersion()for versioning - Avoid direct instantiation of random or time
- Use workflow methods for all non-deterministic operations
Activity Implementation
Activity Implementation
- Make activities idempotent when possible
- Implement heartbeats for long-running activities
- Use dependency injection for testability
- Handle exceptions appropriately
Spring Boot Integration
Spring Boot Integration
- Use Spring’s dependency injection for activities
- Configure workers as Spring components
- Externalize configuration to application.properties
- Implement health checks for workers
Performance Tuning
Performance Tuning
- Adjust worker pool sizes based on load
- Use local activities for fast operations
- Enable sticky execution for better performance
- Monitor metrics and adjust accordingly
Next Steps
Core Concepts
Understand workflows, activities, and task lists
Go Client
Explore the Go SDK for cloud-native apps
CLI Reference
Manage workflows with the Cadence CLI
Operations
Monitor and operate Cadence in production