Sunday, December 2, 2007

JSP - Synchronization

By default JSP pages are Multithreaded(Multi-thread model), ie they are not synchronized.

Normally if we need to make a class synchronized, we implement SingleThreadModel interface.

In JSP, if that page has to be synchronized, we should add

<%@page isThreadSafe="false"%>

Or,

If some code inside the JSP page has to be synchronized, then the Implicit object "page" can be made use of.

<%
synchronized(page)
{
//code that needs to be synchronized
}
%>

No comments: