Java サーブレットのインスタンスの数

Java サーブレットのインスタンスの数

-第3章 Servletインターフェイス (The Servlet Interface)
--http://www.cresc.co.jp/tech/java/ServletSpecificationV2.2/Section_03.htm
--->3.2 インスタンスの数 (Number of Instances)
--->デフォルトとしては、ひとつのコンテナ内の、サーブレット定義(Servletインターフェイスを実装したクラス名と、それに関連する初期化パラメタ)あたりのサーブレット クラスのインスタンスは唯一つでなければならない。
--->SingleThreadModelインターフェイスを実装したサーブレットの場合は、サーブレットコンテナは該サーブレットのインスタンスを複数インスタンス化し、一方では要求を単一のインスタンスにシリアル化しつつ、大量の要求の重負荷を処理する。
--->組込み記述子(deployment descriptor)にdistributableとしてマークし、アプリケーションの一部としてサーブレットが導入されたときは、コンテナには、Java仮想マシン(VM)あたりのサーブレット定義あたりのサーブレットクラスのインスタンスはひとつである。もしサーブレットが配布可能なWebアプリケーションであるとともに、SingleThreadModelインターフェイスを実装しているときは、該コンテナの各仮想マシン内では、該コンテナは該サーブレットの複数のインスタンスをインスタンス化させても良い。

-スレッド対応
--http://www.cresc.co.jp/tech/java/Servlet_Tutorial/Lesson_60.htm
--->サーブレットAPIにはSingleThreadModelというインターフェイスが用意されている。このインターフェイスを実装(implement)すると、下図のようにエンジンはコンテナ上にそのサーブレットの複数のインスタンスのプールを用意し、ひとつのサーブレットのオブジェクトにはひとつのスレッドしかアクセスしないよう制御する。
--->何個のインスタンスを生成するか(WebSpereでは4個以上であった)、それ以上のHTTP要求がきたらどうするか(多分待ち行列に入れる)はサーブレット・エンジンの実装の問題である。こうすればインスタンス変数の共有問題は解決できるが、それ以外の外部資源の共有問題の解決にはならないことに注意しよう。

-The Java Servlet API White Paper
--http://java.sun.com/products/servlet/whitepaper.html

-Java Servlet Technology - Implementations & Specifications
--http://java.sun.com/products/servlet/reference/api/

-The Java Community Process(SM) Program - JSRs: Java Specification Requests - detail JSR# 154
--http://jcp.org/en/jsr/detail?id=154
--->JSR 154: Java Servlet 2.4 Specification

-JSR-000154 Java Servlet 2.4 Specification - Final Release
--http://jcp.org/aboutJava/communityprocess/final/jsr154/
--->SRV.2.2 Number of Instances
--->
--->The servlet declaration which is part of the deployment descriptor of theWeb application
--->containing the servlet, as described in Chapter SRV.13, “Deployment
--->Descriptor”, controls how the servlet container provides instances of the servlet.
--->For a servlet not hosted in a distributed environment (the default), the servlet
--->container must use only one instance per servlet declaration. However, for a servlet
--->implementing the SingleThreadModel interface, the servlet container may
--->instantiate multiple instances to handle a heavy request load and serialize requests
--->to a particular instance.
--->
--->In the case where a servlet was deployed as part of an application marked in
--->the deployment descriptor as distributable, a container may have only one instance
--->per servlet declaration per Java Virtual Machine (JVMTM). However, if the servlet
--->in a distributable application implements the SingleThreadModel interface, the
--->container may instantiate multiple instances of that servlet in each JVM of the
--->container.
--->
--->SRV.2.2.1 Note About The Single Thread Model
--->The use of the SingleThreadModel interface guarantees that only one thread at a
--->time will execute in a given servlet instance’s service method. It is important to
--->note that this guarantee only applies to each servlet instance, since the container
--->may choose to pool such objects. Objects that are accessible to more than one servlet
--->instance at a time, such as instances of HttpSession, may be available at any particular
--->time to multiple servlets, including those that implement
--->SingleThreadModel.
--->It is recommended that a developer take other means to resolve those issues instead
--->of implementing this interface, such as avoiding the usage of an instance variable or
--->synchronizing the block of the code accessing those resources. The
--->SingleThreadModel Interface is deprecated in this version of the specification.

-Servlet/JSPのフレームワークを語るスレ
--http://pc5.2ch.net/tech/kako/1001/10019/1001950590.html
--->で、私なりの結論を言うと、アプリケーションはServletのインスタンスの数に依存しないように
作れるようにしておくべきだと思います。

-Sun ONE Application Server 7 Web アプリケーション開発者ガイド: サーブレットの使用法
--http://docs.sun.com/source/817-0604/dwservlt.html
--->SingleThreadModel クラスを使ってシングルスレッドのサーブレットを作成します。シングルスレッドのサーブレットを Sun ONE Application Server に配備すると、サーブレットエンジンは受信要求に備えてサーブレットインスタンスをプールします。つまり、同じサーブレットの複数のコピーをメモリー内に用意します。このプール内のサーブレットインスタンスの数は、Sun ONE Application Server 固有の Web アプリケーション配備記述子の singleThreadedServletPoolSize プロパティを設定することによって変更できます。Sun ONE Application Server の Web アプリケーション配備記述子の詳細については、「Web モジュールの構築と配備」を参照してください。シングルスレッドのサーブレットは、新規要求を処理するためにインスタンスの空きを待つ必要があるため、その負荷によって動作が遅くなります。ただし、ロードバランスが有効な分散アプリケーションでは、ビジーでないプロセスに負荷が自動的に移行するため、これが問題になることはありません。

-docs.sun.com: Sun Java System Web Server 7.0 管理ガイド
--http://docs.sun.com/app/docs/doc/820-0875/6ncj8d0co?l=ja&a=view
---サーブレットプールサイズ: SingleThreadedServlet ごとにインスタンス化するサーブレットインスタンスの数。値の範囲は 1 から 4096 までです。

-SingleThreadModel
--http://www.nilab.info/wiki/SingleThreadModel.html