News for hackers. Stuff that matters.
Re:Java 21 Virtual Threads – Dude, Where's My Lock? by krackers on Monday July 29, 2024 @07:36PM (#41104734)
What was the solution? If you are creating many virtual threads which might indirectly end up using locks/synchronized, it seems like this is a solution that one could easily encounter
Re:Java 21 Virtual Threads – Dude, Where's My Lock? by rezonant on Monday July 29, 2024 @07:45PM (#41104765)
The solution isn't stated specifically, but either the underlying lock primitives need to be changed to address the synchronization block pinning of virtual threads in their selection of which lock requester wins, or the application developer needs to avoid obtaining a contentious lock within a synchronized block.
Re:Java 21 Virtual Threads – Dude, Where's My Lock? by krackers on Monday July 29, 2024 @07:52PM (#41104802)
>the application developer needs to avoid obtaining a contentious lock within a synchronized block.

The promise of virtual threads was that you could use existing libraries and mostly have things "just work", so relying on the developer to know about the internal synchronization behavior of all transitive libraries used seems risky. Is the former something that is being worked on for jdk23 (the article only vaguely suggests that they will "hopefully addresses the integration between virtual threads and locking primitives.")

Re:Java 21 Virtual Threads – Dude, Where's My Lock? by sitta on Monday July 29, 2024 @08:47PM (#41105094)
Yeah, currently you have to be really careful about what you do in virtual threads. However, they are actively working on a solution to the issue with synchronized blocks. Once that's been solved, they should be a lot easier to use. Unfortunately, many of us will be stuck on 21 for some time now, and will need to continue to worry about synchronized blocks.