[concurrency-interest] Please, help me about Servlet Concurrent Problem.

zuxiong lin linzuxiong1988 at gmail.com
Mon Jun 20 09:09:16 EDT 2011


One thread use the new HashMap , no others , so each thread access one map
in the memory.
I actually want to ask like the servlet ,because the httpServlet  use
threads  in WebContainer  , such as tomcat , jboss .
Client A (Computer A) : http://8.8.8.8:8080/ListServelt?userId=001
Client B (Computer B) : http://8.8.8.8:8080/ListServelt?userId=009
So the thread A for Client A and the thread B for Client B access  the two
different map of the memory instance .
No concurrent enviroment because the two threads access their own map.
Right?Right?Right?

Codes :
public class ListServlet extends HttpServlet {
    private static final long serialVersionUID = 9035149672042103851L;
    protected void *service*(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
IOException {
        String userId = request.getParameter("userId");
        *Map files = GlobalContext.getServiceImpl().getFiles(userId);*
*        response.getWriter().print(files.toString());*
    }
}
public class ServiceImpl {
    public Map getFiles(String userId) {
       * Map m = new HashMap();*
*        m.put(userId, userId);*
*        return m;*
    }
}
public class GlobalContext {
    static ServiceImpl serviceImpl;
    static {
        serviceImpl = new ServiceImpl();
    }
    public static ServiceImpl getServiceImpl() {
        return serviceImpl;
    }
}

Have a good day.
Look forward your reply.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110620/924bb018/attachment.html>


More information about the Concurrency-interest mailing list