バグを掘り下げながら、私はSpring 3.0.5のソースコードDelegatingFilterProxy
に出くわしましたが、パフォーマンスのボトルネックがあるのかどうかは疑問です。 Spring DelegatingFilterProxyマルチスレッドに関する懸念
doFilter()
メソッドを呼び出すようにしようとしていることを前提としなければならない(もちろん
<filter>
宣言、あたり)。
は、今のコードを見て:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
// Lazily initialize the delegate if necessary.
Filter delegateToUse = null;
synchronized (this.delegateMonitor) {
if (this.delegate == null) {
WebApplicationContext wac = findWebApplicationContext();
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
}
this.delegate = initDelegate(wac);
}
delegateToUse = this.delegate;
}
// Let the delegate perform the actual doFilter operation.
invokeDelegate(delegateToUse, request, response, filterChain);
}
synchronized (this.delegateMonitor)
ブロックは、すべての労働者は、彼らが入ることを許可されるまで、辛抱強くアップキューを余儀なくされていることを意味しているすべてのスレッドで渡さなければなりません。
かかわらず、豆の検索はここで行われるために必要な理由の私はの使用は、並列実行の賛成で回避されている可能性があることを疑う - だけのルックアップの場合にthis.delegate
揮発性および使用の同期を行うことによるものであってもよい行われる必要があります。
私は間違った木を吠えますか?すべての入力をいただければ幸いです。
をコミットを参照してください春4
にダブルチェックして修正されています。自由にしてください。パフォーマンスの影響については、私が愛している「Java Concurrency in Practice」の本を思い出してください。スレッドの中断や再活動化は、オブジェクト割り当てのようなものに比べてクロックサイクルで膨大です。また、可能な限り同期ブロックを避ける 'AtomicLong'や' ConcurrentHashMap'のようなクラスを見ると、私には同じ方向性が与えられます。 – user1085804