volatile « Variable « JSP-Servlet Q&A





1. volatile variable in a Servlet    coderanch.com

I have a Servlet which will respond to GET calls by returning the current version. The current version is maintained in a volatile member variable. public class BadAssServlet extends HttpServlet { private volatile Revision m_revision = new Revision( DEFAULT_REV ); ...snipped... } About 99% of the calls to this servlet will be GET calls asking for the current value in m_revision. ...

2. Servlet instance variables and volatile    coderanch.com

Hi everybody, Here is the code from SUN Java EE tutorial demonstrating how to initialize A Servlet. public class CatalogServlet extends HttpServlet { private BookDBAO bookDB; public void init() throws ServletException { bookDB = (BookDBAO)getServletContext().getAttribute("bookDB"); if (bookDB == null) throw new UnavailableException("Couldnt get database."); } } Why bookDB hasn't been made volatile? The variable bookDB has been set by a thread ...