< Prev
Next >

JSP isThreadSafe Attribute of Page Directive

In JSP, the isThreadSafe attribute of page directive is used to indicate if your code is thread safe or not. The isThreadSafe attribute can be given either of the two boolean values : true or false.

Syntax of isThreadSafe

<%@ page isThreadSafe = "true|false" %>

isThreadSafe = "true"

As you know that every JSP page eventually converts to its equivalent Servlet. Hence, when isThreadSafe is set to "true", it indicates that your JSP code is thread safe and can be simultaneously accessed by multiple threads at the same time.

Note - By setting the isThreadSafe to true only indicates but doesn't make a JSP page thread-safe. In order to ensure a thread safe access to a JSP page, the programmer will still have effectively use the synchronized keyword to make sure the synchronized access by multiple threads wishing to execute the JSP simultaneously.

isThreadSafe = "false"

when isThreadSafe is assigned a boolean value false , the servlet resulting from JSP page will implement SingleThreadModel interface. It indicates that your code is not thread safe and hence it should not be concurrently accessed by multiple threads.


isThreadSafe example

We are setting isThreadSafe attribute to false to indicate that our JSP page is not thread-safe.


<title>JSP isThreadSafe Attribute</title>


<%@ page isThreadSafe = "false" %>

<b>Setting isThreadSafe attribute to false indicates that this JSP page is not thread safe 
and should not be concurrently accessed by multiple threads.</b>.



executing the above mentioned JSP web page will indicate the container that JSP page is thread safe.


By default, the value of isThreadSafe Attribute is true, which indicates that your JSP web page is thread-safe.

Please share this article -

< Prev
Next >
< JSP contentType Attribute
JSP session Attribute >


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition