< 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.

ThreadSafe.jsp
<html>

<head>
<title>JSP isThreadSafe Attribute</title>
</head>


<body>

<%@ 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>.

</body>

</html>



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




Note


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




Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter



< Prev
Next >
< JSP contentType Attribute
JSP session Attribute >
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2