Skip to Content
Javaパフォーマンス第2版
book

Javaパフォーマンス第2版

by Scott Oaks
March 2025
Intermediate to advanced
450 pages
7h 10m
Japanese
O'Reilly Media, Inc.
Content preview from Javaパフォーマンス第2版

第10章 Javaサーバー Javaサーバ

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

この章では、Javaサーバー技術にまつわるトピックを探求する。 これらの技術の核心は、クライアント、サーバー間で、通常HTTPを介してデータを伝送する方法に関するものである。従って、この章では一般的なサーバー技術に共通するトピックに主眼を置いている。異なるスレッドモデルを使ったサーバーのスケール方法、非同期レスポンス、非同期リクエスト、JSONデータの効率的な処理などである。

サーバのスケーリングは、スレッドの効果的な使用に関するものであり、その使用にはイベント駆動のノンブロッキングI/Oが必要である。Apache Tomcat、IBM WebSphere Application Server、Oracle WebLogic Serverといった従来のJava/Jakarta EEサーバは、かなり以前からJava NIO APIを使ってそれを実現してきた。NettyやEclipse Vert.xのような現在のサーバフレームワークは、Java NIO APIの複雑さを分離し、より小さなフットプリントのサーバを構築するための使いやすい構成要素を提供している。Spring WebFluxやHelidonのようなサーバは、スケーラブルなJavaサーバを提供するために、これらのフレームワーク(どちらもNettyフレームワークを使用する)上に構築されている。

これらの新しいフレームワークは、リアクティブ・プログラミングに基づいたプログラミング・モデルを提供している。リアクティブ・プログラミングの核心は、イベントベースのパラダイムを使って非同期データストリームを処理することにある。リアクティブ・プログラミングと非同期プログラミングは、イベントの見方が異なるが、私たちの目的では、リアクティブ・プログラミングも非同期プログラミングも同じ性能上の利点がある。

Java NIOの概要

ノンブロッキングI/Oの仕組みに詳しい人は、次のセクションに飛んでも構わない。そうでない場合は、この章の基礎として、その仕組みと重要な理由を簡単に説明する。

Javaの初期バージョンでは、I/Oはすべてブロックだった。ソケットからデータを読み取ろうとするスレッドは、少なくともいくつかのデータが利用可能になるか、 読み取りがタイムアウトするまで待つ(ブロックする)。さらに重要なことは、ソケットからの読み取りを試みなければ、ソケットでデータが利用可能かどうかを知る方法がないということである。そのため、クライアントコネクション上でデータを処理したいスレッドは、データを読み取るリクエストを発行し、データが利用可能になるまでブロックし、リクエストを処理してレスポンスを返送し、その後、ソケット上でブロッキングされた読み取りに戻る必要がある。図10-1のような状況になる。

Threads blocking on I/O reads from clients
図10-1. クライアントからのI/O読み取りでブロックするスレッド

I/Oをブロックするためには、サーバはクライアント接続とサーバスレッドを1対1で対応させる必要がある。これは、HTTPキープアライブを使用して、リクエストごとに新しい ソケットを作成することによるパフォーマンスへの影響を避けたいクライアント ...

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

スクラム実践者が知るべき97のこと

スクラム実践者が知るべき97のこと

Gunther Verheyen, 吉羽 龍太郎, 原田 騎郎, 永瀬 美穂

Publisher Resources

ISBN: 9798341626010