In the below code if I don't use synchronized (this) what will happen? Is this servlet correctly cover servlet rule ?
Integer counter = new Integer(0);// instance variable
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html><head><title>Calculate Number of Times Visits Using Session</title></head><body>");
HttpSession visitSession = request.getSession(true);
if(visitSession.isNew())
out.println("This is the first time you are visiting this page.");
else
out.println("Welcome back to this page");
synchronized(this) {
out.println("<br><br>You have visited this page " + (++Counter));
out.println((Counter == 1) ? " time " : " times ");
}
out.println("</body></html>");
} finally {
out.close();
}
}