Can I avoid problems with concurrent access to bean variables by implementing the SingleThreadModel? Or can the scope attribute be used to ensure that the same bean cannot be concurrently used by more than one thread?

Ryan Breidenbach

First, let me address the SingleThreadModel question. This interface really does not address the issue of concurrent access to JavaBeans is a JSP application. To cite the documentation of this interface directly:

If a servlet implements this interface, the servlet will be thread safe. However, this interface does not prevent synchronization problems that result from servlets accessing shared resources such as static class variables or classes outside the scope of the servlet.
In other words, access to a servlet's instance variables is thread safe, but that is it.

Now, in response to your other question about scope... Most times your scope will be page, request or session. In each of these, you will probably only have one thread handling the JavaBean - the thread handling the HttpServletRequest. However, if a Bean has application scope (acessible from multiple servlets in the application) you need to synchronize access to this Bean.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact