-
Notifications
You must be signed in to change notification settings - Fork 322
Quickstart
agapple edited this page Oct 8, 2013
·
2 revisions
1. asyncload是做为一个jar包形式,做为工具包提供,非独立服务.
2. asyncload的工作原理主要为切面拦截,所以需要在原先的代码中进行埋点,比如可以人为控制异步并发的粒度. (区别于协程的重编译模式)
1. 下载jar包
maven工程,groupId/artifactId信息:
<dependency> <groupId>com.alibaba.asyncload</groupId> <artifactId>asyncload</artifactId> <version>x.y.z</version> </dependency>
非maven工程:
访问:http://central.maven.org/maven2/com/alibaba/asyncload/asyncload/,选择对应的版本进行下载.
2. 加入spring配置
比如新增spring配置文件bean-asyncload.xml
定义配置:
<?xml version="1.0" encoding="GB2312"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans default-autowire="byName"> <!-- async相关配置 --> <bean id="asyncLoadExecutor" class="com.alibaba.asyncload.AsyncLoadExecutor" init-method="initital" destroy-method="destory"> <property name="poolSize" value="10" /> <!-- 异步线程池大小 --> <property name="acceptCount" value="100" /> <property name="mode" value="REJECT" /> </bean> <bean id="asyncLoadConfig" class="com.alibaba.asyncload.AsyncLoadConfig"> <property name="defaultTimeout" value="0" /> <property name="needThreadLocalSupport" value="false" /> <property name="needBarrierSupport" value="false" /> </bean> <!-- 异步加载模板类 --> <bean id="asyncLoadTemplate" class="com.alibaba.asyncload.impl.template.AsyncLoadTemplate" > <property name="executor" ref="asyncLoadExecutor" /> <property name="config" ref="asyncLoadConfig" /> </bean> <!-- 并行加载拦截器 --> <bean id="asyncLoadInterceptor" class="com.alibaba.asyncload.impl.spring.AsyncLoadInterceptor" > <property name="asyncLoadTemplate" ref="asyncLoadTemplate" /> </bean><bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="optimize" value="false"/> <property name="proxyTargetClass" value="false" /> <property name="beanNames"> <list> <value>xxxService</value> <!-- 指定具体需要做异步拦截的service bean即可 --> </list> </property> <property name="interceptorNames"> <list> <value>asyncLoadInterceptor</value> </list> </property> </bean>
</beans>
3. spring的applicationContext中locations加入bean-asyncload.xml,使其生效即可.
具体详细的配置可参见:用户手册