【发布时间】:2012-11-05 15:53:00
【问题描述】:
我有一个执行各种业务逻辑的 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);
}
我不会使用任何静态变量,并且我的所有方法调用都假定是线程安全的。有什么不明显的缺点吗?
【问题讨论】:
标签: servlets concurrency static synchronized