我有一个执行各种业务逻辑的 servlet。我想避免这样的同步:
@Override
protected void doGet(final HttpServletRequest _req, final HttpServletResponse _resp) throws ServletException, IOException {
synchronized (MyServlet.class) {
various();
calls();
and_logic(_req, _resp);
}
}
通过将所有调用的方法设为静态并像这样强制执行它:
@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);
}
我不会使用任何静态变量,并且我的所有方法调用都被假定为线程安全的。有什么不明显的缺点吗?