Thread management in reactive code.

Overview

Thread management in reactive code.

Example

  Flux.just(1, 2, 3)
    .map(i -> i * 2)
    .filter(i -> i > 2)
    .subscribe(System.out::println);
  

Common Use Cases

  • High-concurrency I/O
  • Streaming data processing
  • Microservices with many concurrent calls

Pitfalls to Avoid

  • Blocking calls inside reactive chains
  • Subscribing multiple times to cold publishers
  • CompletableFuture
  • Virtual threads
  • Spring MVC

Best Practices

  • Understand when to use schedulers versus simpler alternatives
  • Write unit tests covering edge cases and failure paths
  • Follow Java conventions and prefer standard library APIs when available
  • Profile before optimizing — measure impact in your specific workload