Java Servlets

Synchronicity Problems

  1. Synchronize method:
    public synchronized void doGet(HttpServletRequest req,
                                   HttpServletResponse res)
    
  2. Synchronize code:
    PrintWriter out = res.getWriter();
    synchronized(this) {
      count++;
      out.printl(...);
    }
    
  3. Synchronize only needed functionality:
    PrintWriter out = res.getWriter();
    int local_count;
    synchronized(this) {
      local_count = ++ count;}
    out.println(..);
    
  4. Live with it.

José M. Vidal .

18 of 89