Skip to content

jjvogel/java-order-processing-demo-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Order Processing Demo

A Java 21 order analytics pipeline built to demonstrate common performance anti-patterns and how to find them with JDK Flight Recorder (JFR) and JDK Mission Control (JMC).

This app was originally built for a DevNexus 2026 talk (March 10, 2026) and is the demo application referenced in the blog series:

What's in this repo

The main branch contains the unoptimized code with intentional performance anti-patterns on the hot path:

  • O(n²) stream-inside-loop in TrendDetector.detect()
  • String concatenation with + in a loop in RevenueAnalyzer.analyze()
  • Pattern.compile() on every call in OrderValidator.validate()
  • String.format() in a hot path in OrderGenerator.generateOrder()
  • Autoboxing with List<Double> / List<Integer> in FraudScorer.score()
  • synchronized method with string concatenation in AnalyticsAccumulator.accumulate()
  • LinkedList with indexed access and Hashtable in ReportGenerator.generate()

The performance-optimized branch contains the fixes. Run git diff main..performance-optimized to see exactly what changed.

Prerequisites

java -version    # should show 21.x
mvn -version     # should show 3.8+

Build and Run

mvn clean package
java -cp target/classes com.demo.orderanalytics.App

This processes 100,000 orders across 100 batches using virtual threads and prints throughput metrics and an analytics report.

Custom configuration

java -cp target/classes com.demo.orderanalytics.App \
  --orders 200000 \
  --batch-size 2000
Flag Default Description
--orders <n> 100000 Total orders to process
--batch-size <n> 1000 Orders per batch
--profile off Enable JFR recording via the app's built-in controller
--output <path> recording.jfr JFR output file path

Profiling with JFR and JMC

Capture a recording

Use the JDK's built-in profile settings for comprehensive event capture (CPU sampling, allocation tracking, GC events, thread contention):

java -XX:StartFlightRecording=filename=recording.jfr,settings=profile \
  -cp target/classes com.demo.orderanalytics.App

Open in JMC

  1. Download JDK Mission Control
  2. File → Open File → select recording.jfr
  3. Start with the Java Application overview tab (CPU, heap, GC)
  4. Go to Method Profiling for the flame graph
  5. Go to Lock Instances (under Threads) for contention data

A pre-captured recording.jfr is included in this repo from the unoptimized baseline. You can open it in JMC immediately to see the anti-patterns in action.

Reproduce the contention data

The default config (100 virtual threads) may not generate enough lock contention to cross JFR's reporting threshold. To see contention on AnalyticsAccumulator, run with higher concurrency:

java -XX:StartFlightRecording=filename=contention.jfr,settings=profile \
  -cp target/classes com.demo.orderanalytics.App \
  --orders 500000 --batch-size 200

Then open contention.jfr in JMC and navigate to Threads → Lock Instances.

License

MIT

About

Java 21 order analytics demo with intentional performance anti-patterns. Companion code for the Java Performance blog series.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

No contributors

Languages