0

I have a servlet which performs various business logic. I want to avoid synchronisation like this:

@Override
protected void doGet(final HttpServletRequest _req, final HttpServletResponse _resp) throws ServletException, IOException {
     synchronized (MyServlet.class) {
         various();
         calls();
         and_logic(_req, _resp);
     }
}

by making all called methods static and enforcing it like this:

@Override
protected void doGet(final HttpServletRequest _req, final HttpServletResponse _resp) throws ServletException, IOException {
    _doGet(_req, _resp);
}

private static void _doGet(final HttpServletRequest _req, final HttpServletResponse _resp) throws ServletException, IOException {
     various();
     calls();
     and_logic(_req, _resp);
}

I won't use any static variables and all my method calls are assumed to be thread-safe. Are there any non-obvious drawbacks?

4

1 に答える 1

1

I won't use any static variables and all my method calls are assumed to be thread-safe.

Under these conditions neither you don't need synchronization nor static methods. Just use instance methods of a servlet or some other service class.

于 2012-11-05T16:06:00.767 に答える