List of usage examples for org.springframework.aop.interceptor ConcurrencyThrottleInterceptor ConcurrencyThrottleInterceptor
public ConcurrencyThrottleInterceptor()
From source file:org.springframework.aop.interceptor.ConcurrencyThrottleInterceptorTests.java
@Test public void testSerializable() throws Exception { DerivedTestBean tb = new DerivedTestBean(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setInterfaces(new Class[] { ITestBean.class }); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); proxyFactory.addAdvice(cti);// w ww . jav a2 s. com proxyFactory.setTarget(tb); ITestBean proxy = (ITestBean) proxyFactory.getProxy(); proxy.getAge(); ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy); Advised advised = (Advised) serializedProxy; ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0] .getAdvice(); assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit()); serializedProxy.getAge(); }
From source file:org.springframework.aop.interceptor.ConcurrencyThrottleInterceptorTests.java
private void testMultipleThreads(int concurrencyLimit) { TestBean tb = new TestBean(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setInterfaces(new Class[] { ITestBean.class }); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); cti.setConcurrencyLimit(concurrencyLimit); proxyFactory.addAdvice(cti);//w ww.j av a2s . c o m proxyFactory.setTarget(tb); ITestBean proxy = (ITestBean) proxyFactory.getProxy(); Thread[] threads = new Thread[NR_OF_THREADS]; for (int i = 0; i < NR_OF_THREADS; i++) { threads[i] = new ConcurrencyThread(proxy, null); threads[i].start(); } for (int i = 0; i < NR_OF_THREADS / 10; i++) { try { Thread.sleep(5); } catch (InterruptedException ex) { ex.printStackTrace(); } threads[i] = new ConcurrencyThread(proxy, i % 2 == 0 ? (Throwable) new OutOfMemoryError() : (Throwable) new IllegalStateException()); threads[i].start(); } for (int i = 0; i < NR_OF_THREADS; i++) { try { threads[i].join(); } catch (InterruptedException ex) { ex.printStackTrace(); } } }