버그를 찾아 내면서 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)
블록은 그들이 입력 할 수 있습니다 때까지 모든 근로자가 참을성 대기열을 강요하는 것을 의미하는 모든 스레드에 의해 전달되어야합니다. 에 관계없이 필요한 콩 조회가 여기에 수행 될 이유
내가 synchronized
의 사용이 병렬 실행에 찬성 피할 수 있다고 생각한다 - 만 조회의 경우 this.delegate
휘발성 및 사용 동기화함으로써 될 수있다 할 필요가있다 .
그래서 나는 잘못된 나무를 짖고 있습니까? 모든 입력을 부탁드립니다.
를 저지를 참조 봄 4
두 번 검사로 수정되었습니다. 자유롭게 그렇게하십시오. 성능 영향과 관련하여 필자는 사랑스런 'Java Concurrency in Practice'서적에서 객체 할당과 비교하여 스레드를 일시 중단하고 다시 활성화하는 것이 클럭주기에 엄청나다는 것을 상기합니다. 또한 가능한 한 동기화 된 블록을 피하는'AtomicLong' 또는'ConcurrentHashMap'과 같은 클래스를 보면 저에게 같은 방향을 제공합니다. – user1085804