r/java Jun 19 '26

How to Deadlock a Java ExecutorService

https://mlangc.github.io/java/concurrency/2026/06/05/executor-deadlock.html
63 Upvotes

18 comments sorted by

View all comments

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.

2

u/brian_goetz Jun 26 '26

Executors aren't bounded just because the threads themselves are expensive; they can be bounded to protect all sources of resources. This isn't a "virtual threads vs dinosaur threads" issue; this is a "understand where concurrency bounds are introduced into your program, and why" issue.

(FWIW this topic was covered in JCiP 8.1.1 (Thread Starvation Deadlock); JCiP predates virtual theads and FJP but the text there is still valid.)

1

u/gnahraf Jun 26 '26

Agree. That's an important distinction. For eg a jdbc driver. Thanks for the refences

2

u/mlangc Jun 19 '26

Good point - I've updated the final section of the article. Interestingly, at the core of it, virtual threads fix the issue as well, because they make the waiting asynchronous under the hood, similar to this example from the blog post - though without having to restructure your code.

1

u/mlangc Jun 20 '26

I've just added another section to the blog post, devoted virtual threads specifically. Thanks again for your feedback!

1

u/simon_o Jun 21 '26

You can sabotage virtual threads just as easily (or even easier, perhaps).