Skip to content

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>
&lt;bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;
	&lt;property name="optimize" value="false"/&gt;
	&lt;property name="proxyTargetClass" value="false" /&gt;
    &lt;property name="beanNames"&gt;
    	&lt;list&gt;
    		&lt;value&gt;xxxService&lt;/value&gt; &lt;!-- 指定具体需要做异步拦截的service bean即可 --&gt;
    	&lt;/list&gt;
    &lt;/property&gt;
    &lt;property name="interceptorNames"&gt;
    	&lt;list&gt;
            &lt;value&gt;asyncLoadInterceptor&lt;/value&gt;
    	&lt;/list&gt;
    &lt;/property&gt;
 &lt;/bean&gt;

</beans>

3. spring的applicationContext中locations加入bean-asyncload.xml,使其生效即可.

具体详细的配置可参见:用户手册

Table of Contents

* Home * Introduction * QuickStart * ChangeLog * 用户手册
Clone this wiki locally