Clojure 1.12.0-alpha5
Clojure 1.12.0-alpha5 is now available and we encourage you to try it and give us your feedback! Use locks instead of synchronized blocks around user code in lazy-seq and delay Clojure users want to use virtual threads on JDK 21. Prior to 1.12, Clojure lazy-seqs and delays, in order to enforce run-once behavior, ran user code under synchronized blocks, which don’t participate in cooperative blocking. Thus if that code did e.g. blocking I/O it would pin a real thread. JDK 21 may emit warnings for this when using -Djdk.tracePinnedThreads=full . To avoid this pinning, in 1.12 we’ve changed lazy-seqs and delay to use locks instead of synchronized blocks.

Clojure 1.12.0-alpha5 has been released, marking a significant update that introduces several improvements and changes to the language. The development team is eager for users to try out this new version and provide feedback to ensure the best possible experience. One of the key changes in this release is the shift from using synchronized blocks to locks around user code in lazy-seq and delay. This modification is aimed at addressing potential issues related to blocking I/O operations and improving compatibility with JDK 21's virtual threads.
Prior to the 1.12 release, Clojure's lazy-seq and delay constructs enforced a run-once behavior by executing user code under synchronized blocks. However, synchronized blocks do not participate in cooperative blocking, which means that if the user code performed blocking operations like I/O, it would pin a real thread. This could lead to inefficiencies and potential issues, especially with the advent of JDK 21. With the introduction of the -Djdk.tracePinnedThreads=full flag in JDK 21, warnings may be emitted for such pinned threads.
To prevent this pinning and ensure better compatibility with JDK 21's virtual threads, the Clojure team has opted to replace synchronized blocks with locks in lazy-seq and delay. This change ensures that blocking operations within these constructs do not pin real threads, thus improving overall performance and avoiding the warnings generated by JDK 21. This update is particularly important for Clojure users who plan to leverage virtual threads in their applications, as it ensures smoother integration and better performance.
The release of Clojure 1.12.0-alpha5 also highlights the ongoing commitment of the development team to refining the language and addressing user feedback. By encouraging users to try the new version and provide insights, the team aims to create a more robust and efficient Clojure ecosystem. As the alpha phase progresses, the community can expect further iterations and improvements based on the feedback received.
In conclusion, Clojure 1.12.0-alpha5 introduces a notable change by replacing synchronized blocks with locks in lazy-seq and delay, addressing potential thread-pinning issues and improving compatibility with JDK 21's virtual threads. This update underscores the language's continuous evolution and the importance of community involvement in shaping its future. As users adopt and test this new version, the Clojure community can look forward to a more efficient and robust platform for development.










