※当サイトの記事には、広告・プロモーションが含まれます。

JDK 21でVirtual Threadsが正式リリースし、Spring Boot 3.2でVirtual Threadsに対応したそうな

news.mynavi.jp

⇧ amazing...

Virtual Threadsとは?

公式の情報によりますと、

openjdk.org

Summary

Introduce virtual threads to the Java Platform. Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.

https://openjdk.org/jeps/444

Goals

  • Enable server applications written in the simple thread-per-request style to scale with near-optimal hardware utilization.

  • Enable existing code that uses the java.lang.Thread API to adopt virtual threads with minimal change.

  • Enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK tools.

https://openjdk.org/jeps/444

⇧ とのこと。

blog.payara.fish

There are several more advantages. Less memory is required for multiple threads, it is kept in Java heap instead of limited native memory. They are kept in Java, so they don’t reach the Thread’s OutOfMemory if too many of them are used.

https://blog.payara.fish/a-look-at-virtual-threads-in-a-jakarta-ee-managed-context

⇧ 省メモリってことらしいんだけど、Heapを利用しているんなら、OutOfMemoryが起こりやすくなりそうな気がするんだけど、OutOfMemoryになりにくいと謳っておりますな。

Spring Boot 3.2でVirtual Threadsに対応したそうな

何やら、

spring.io

It works just fine with existing versions of Spring Boot, but the real payoff will be with Spring Boot 3.2, where you'll be able to plug in virtual threads with nary but a flick of a property: spring.threads.virtual.enabled=true. Spring Boot 3.2 drops in November. Get ready!

https://spring.io/blog/2023/09/19/this-week-in-spring-september-19th-2023-java-21-edition/

⇧ とあるように、Spring Boot 3.2でVirtual Threadsを有効にできるようになったらしい。

ただ、上記の設定だと、部分的にVirtual Threadsを適応したい場合とかに対応ができないってことなんでしょうね。

Virtual Threadsを使うことが適さないケースがあり、

www.danvega.dev

Where Virtual Threads Don’t Make Sense

We know that Virtual Threads make sense when our applications are performing some type of blocking operation. Where it doesn’t make sense is in a purely CPU intensive application. Another scenario where they don’t make sense is if you’re already using asynchronous programming. In either scenario you can enable them but you won’t see any performance benefits.

https://www.danvega.dev/blog/virtual-threads-spring-boot

⇧ とのこと。

いまいち、Virtual Threadsの使いどころが分かりませんな...

そもそも、JDKのバージョンが21を使っていないとVirtual Threadsが使えないと思うのと、JDKのバージョン21を使っているJavaアプリケーションが少なそうなので、実績も無さそうね...

Java有識者の人が、Virtual Threadsの使いどころなど、情報発信してくれることを期待しますか。

毎度モヤモヤ感が半端ない...

今回はこのへんで。