HttpSessionはスレッドセーフか?#2

以前の日記でも書きましたが、この問題に関する自分のなりの回答を見つけましたので公開します。

SUNのForumからHttpSessionに関する質問見つけたのですが、
この中でこのような回答があります。

Servlets, by default, are multithreaded and can respond simultaneously to multiple users' requests. However, you have to ensure that the methods within your implementation of Servlet or HttpServlet are thread-safe. This means that they do not refer to any instance variables within the Servlet that might change.

As far as sessions, each time you call getSession() or getSession(true) on HttpServletRequest, a UID will be generated by the Servlet container. This will be sent back to the client, either as a re-written URL, a URL parameter or a cookie. On subsequent requests, the client/browser should re-send this token back to the Servlet. In these requests, getSession() or getSession(false) will return the user's original session, located via the UID. You do not have to implement any of the above yourself. It works out of the box. Unless two users get the same random session UID (rare, and should not happen in a proper container) or unless another user attempts to manually hijack another user's session (possible), session data will not get corrupted.

意味としてはSessionのUIDはgetSession()を呼び出すタイミングでサーブレットコンテナが生成しており、このUIDはユーザー毎に生成されているため複数ユーザーが同時にHttpSessionに書き込み等を行ってもUIDが同じリクエストでない限り
データが壊れる等の問題が発生することはないといった感じの事を述べています。


確かに言われてみるとその通りですよね。
ただ注意しなければならないのはやはりここで述べているように同じユーザーが同じUIDを複数もってしまった場合はその限りではないというところでしょう。
例えば一つブラウザを開いた後、そのブラウザから新しいブラウザを開くと同じUIDを使ってしまうことなどはありえるかと思います。
これはHttpSessionがスレッドセーフではないということを意味していると言えます。
ただこのレベルの話になると後はシステムの設計次第になるのでご自由に制御してくださいといったところでしょうか。