KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > interceptor > ConcurrencyThrottleInterceptor


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.interceptor;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.aopalliance.intercept.MethodInterceptor;
22 import org.aopalliance.intercept.MethodInvocation;
23
24 import org.springframework.util.ConcurrencyThrottleSupport;
25
26 /**
27  * Interceptor that throttles concurrent access, blocking invocations
28  * if a specified concurrency limit is reached.
29  *
30  * <p>Can be applied to methods of local services that involve heavy use
31  * of system resources, in a scenario where it is more efficient to
32  * throttle concurrency for a specific service rather than restricting
33  * the entire thread pool (e.g. the web container's thread pool).
34  *
35  * <p>The default concurrency limit of this interceptor is 1.
36  * Specify the "concurrencyLimit" bean property to change this value.
37  *
38  * @author Juergen Hoeller
39  * @since 11.02.2004
40  * @see #setConcurrencyLimit
41  */

42 public class ConcurrencyThrottleInterceptor extends ConcurrencyThrottleSupport
43         implements MethodInterceptor, Serializable JavaDoc {
44
45     public ConcurrencyThrottleInterceptor() {
46         setConcurrencyLimit(1);
47     }
48
49     public Object JavaDoc invoke(MethodInvocation methodInvocation) throws Throwable JavaDoc {
50         beforeAccess();
51         try {
52             return methodInvocation.proceed();
53         }
54         finally {
55             afterAccess();
56         }
57     }
58
59 }
60
Popular Tags