10.6. SingleThreadModel

Earlier in this chapter you learned that servlets can be shared between a potentially large number of client requests that come in through the Web server. For this reason, great care should be used to provide thread-safe code in the servlet. The reasoning behind this is to alleviate the amount of memory needed and reduce unnecessary CPU usage.

In some instances, a servlet developer may find that providing thread-safe code is neither possible nor desirable. In this case, there is the option of implementing the SingleThreadModel interface. This interface is without any explicit operations, and is used only as a marker for the Web server. However, the servlet developer should note that this interface wipes out one of the ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.