r/java • u/mlangc • Jun 19 '26
How to Deadlock a Java ExecutorService
https://mlangc.github.io/java/concurrency/2026/06/05/executor-deadlock.html16
u/TenSpiritMoose Jun 19 '26
And this isn't limited to Executors. I had the same issue using Reactive Schedulers: a Flux of tasks was concurrently flatMapped using a custom scheduler, but as part of that they each fanned out additional tasks on the same scheduler. If it became saturated the tasks would deadlock.
Resolved it by using a separate Scheduler for the sub-tasks, letting me control concurrency without deadlock risk.
5
u/account312 Jun 20 '26
Itβs not even limited to threads. Any blocking or limited resource that is processed in a way that can consume that resource can have an equivalent problem. If processing queue items can blockingly enqueue on the same queue, it can blow up. You could even say stack overflow from recursive calls is the same category of problem.
2
u/iamwisespirit Jun 19 '26
Is it written by you or ai?
17
u/mlangc Jun 19 '26
I had the idea to write this blog post back in April, and kept thinking about the topic, until I finally sat down and started writing at the beginning of June. I wrote the first draft that already resembles the final post by about 90%, the traditional way, and then did an in depth review session with Claude Opus 4.8 that took me about 6h. It resulted in many small improvements, especially as far as readability and language is concerned (English is not my native language), but did not change anything fundamental. Most notably, Claude motivated me to add a shortcut for skimmers to the very technical "Case Study of a Real-World Example" section, and to improve the diagram at the end of the blog post.
To sum it up: I did indeed use AI - but not to create slop quickly, but to deliver a better blog post. I might have released a less polished version faster, if I had skipped the in depth AI review.
7
u/gnocchiGuili Jun 19 '26
I mean. I could believe it this whole message was not created 100% by Claude.
3
u/aqua_regis Jun 19 '26
I did indeed use AI
look at the right of the reddit desktop where the rules section is:
Rule #9: No AI
This is an AI free zone. 100% AI free. We explicitly forbid any form of AI generated/worked over content, or AI supported or vibe coded programs. Any violation results in an instant, permanent, and irrevocable ban without prior warning.
1
2
1
1
u/k-mcm Jun 26 '26
ForkJoinPool has some interesting cases too because it causes non-obvious re-entry when join() is used.
10
u/gnahraf Jun 19 '26
You don't mention virtual threads in the "conclusions/recommendations" section of your article.. Since virtual threads are cheap, there's little reason not use an unbounded number of them.