JSP Thread Safety

Intertech Tutorials

JSP Thread Safety

The isThreadSafe page directive attribute specifies whether the JSP container can send multiple, concurrent requests through the JSP page. In other words, isThreadSafe specifies whether the container can send multiple requests through the generated servlet. The default value is true – meaning the servlet accepts multiple concurrent client requests and the developer must code for thread issues. When set to false, the container sends only a single client request through the servlet at any one time.

The most common way for container providers to implement isThreadSafe is to have the generated servlet implement SingleThreadModel. However, as of Servlet 2.4, SingleThreadModel is deprecated. Therefore, the JSP specification recommends against using isThreadSafe.

“The Servlet 2.4 specification deprecates SingleThreadModel, which is the most common mechanism for JSP containers to implement isThreadSafe. Page authors are advised against using isThreadSafe, as the generated Servlet may contain deprecated code.”

As with servlets, it is considered better practice to code your JSPs to make them thread safe.

Copyright (c) 2008-2013. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.