Skip to Content
Javaにおける現代的な並行処理
book

Javaにおける現代的な並行処理

by A N M Bazlur Rahman
September 2025
Intermediate to advanced
336 pages
5h 49m
Japanese
O'Reilly Media, Inc.
Content preview from Javaにおける現代的な並行処理

第7章. 仮想スレッドを利用する最新のフレームワーク

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

未来を予測する最善の方法は、それを発明することである。

アラン・ケイ

JDK21で仮想スレッドが導入されたことで、Javaエコシステムはフレームワークの並行処理方法に大きな変化を目の当たりにした。最近のフレームワークの多くは、パフォーマンス、スケーラビリティ、リソース効率を改善するために仮想スレッドを採用している。

この章では、Spring Boot、Quarkus、Jakarta EEなどの主要なフレームワークがどのように仮想スレッドを統合しているかを探る。しかし、これらのフレームワークの内部構造には立ち入らない。興味のある人は、各フレームワークを自分で深く調べたいだろうからだ。

始めよう。

Spring Boot

Spring Bootは、Javaエコシステムでエンタープライズアプリケーションを構築するための、 デファクトフレームワークの1つだ。

歴史的に、Spring BootのWebアプリケーションは主にスレッドパーリクエストモデルに従っており、専用のプラットフォームスレッドが各クライアントリクエストを処理する。このアプローチは中程度の負荷ではうまくいくが、大量の同時I/Oバウンドリクエストを処理するときにスケーラビリティの問題が発生する。

これを緩和するために、Spring Bootは非同期プログラミング機能を導入した。 @Asyncのようなアノテーションと抽象化によって非同期プログラミング機能を導入した。 TaskExecutor.しかしこのアプローチでも、次の例に示すように、プラットフォームスレッドの限られたプールに依存していた:

@Configuration
public class ThreadPoolConfig {
    @Bean
    public AsyncTaskExecutor applicationTaskExecutor() {
        
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(100);
        executor.initialize();
        return executor;
    }
}

ここでは、すべてのリクエストやタスクが有限のプールからスレッドを消費し、高負荷時にパフォーマンスのボトルネックになる可能性がある。

2023年11月にSpringフレームワーク6.1をベースに構築されたSpring Boot 3.2がリリースされ、仮想スレッドを最終化したJava 21の公式サポートが導入された。Java 17がベースラインのJDKであることに変わりはないが、Java 21はフレームワーク内でファーストクラスの実行環境として扱われるようになった。このサポートの重要な側面は、仮想スレッドを有効にするためのシンプルな設定プロパティの提供である:

# application.properties
spring.threads.virtual.enabled=true .

またはYAML形式である:

# application.yml
spring:
  threads:
    virtual:
      enabled: true

この設定プロパティをセットすることで、アプリケーション全体で仮想スレッドが有効になる。Spring ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

高リスク分野のための機械学習 ―責任あるAI構築のための実践アプローチ

高リスク分野のための機械学習 ―責任あるAI構築のための実践アプローチ

Patrick Hall, James Curtis, Parul Pandey, 高江洲 勲, 伊東 道明, 園田 道夫, 北條 孝佳, 石川 太一
エンジニアが学ぶ会計システムの「知識」と「技術」

エンジニアが学ぶ会計システムの「知識」と「技術」

広川 敬祐, 五島 伸二, 小田 恭彦, 大塚 晃, 川勝 健司

Publisher Resources

ISBN: 9798341670167