http://download.eclipse.org/jetty/stable-7/xref/com/acme/ChatServlet.htmlを見ると、同期メソッドに同期ブロックが必要な理由がわかりません。 :
private synchronized void chat(HttpServletRequest request,HttpServletResponse response,String username,String message)
throws IOException
{
Map<String,Member> room=_rooms.get(request.getPathInfo());
if (room!=null)
{
// Post chat to all members
for (Member m:room.values())
{
synchronized (m)
{
m._queue.add(username); // from
m._queue.add(message); // chat
// wakeup member if polling
if (m._continuation!=null)
{
m._continuation.resume();
m._continuation=null;
}
}
}
}
メソッド全体がすでにスレッドセーフであるのに、なぜm
同期する必要があるのですか?
洞察をありがとう。