" ); // when you get to 10, throw exception to cause the // this servlet instance to be destroyed and reloaded if( instanceCount > 0 && ( instanceCount / 10 ) > 0 ) { instanceCount = 0; throw new ServletException( "Hit Refresh Again" ); } // synchronize on the servlet instance before updating the counter synchronized( this ) { // number of times this servlet instance has been accessed out.println( "Servlet Instance Count -> " + instanceCount++ ); } // sychronize on the servlet class before updating the class-based counter synchronized( ServletCounter.class ) { // collective total of all accesses to all servlet instances created // by this class out.println( "Servlet Total Request Count -> " + classCount++ ); } out.println( "</body></html>" ); out.close(); } }