首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

motan之异步调用

一、什么是异步调用?  1.同步调用 方法间的调用,假设A方法调用B方法,A方法等待B方法执行完毕后才执行本身,这个同步调用,是具有阻塞式的调用,如果B方法非常耗时,那么整个方法的执行效率将会非常低; 2.异步调用 同样是方法间的调用,假设A方法调用B方法,不同的是A方法调用B方法后,B方法很快的返回给A方法个答复(这个答复不是执行完整个B方法的答复),A方法收到答复后就执行本身,这个是异步调用,不管B方法是否耗时,整体的效率都提升。 二、motan的异步调用入门 1.首先,以入门案例为基础案例改造:http://www.cnblogs.com/Json1208/p/8784906.html 2.motan-api工程HelloWorldService添加注解@MotanAsync 复制代码 package com.motan.service; import com.weibo.api.motan.transport.async.MotanAsync; @MotanAsync public interface HelloWorldService {     String hello(String name); } 复制代码 3.motan-api添加maven插件build-helper-maven-plugin,用来把自动生成类的目录设置为source path 复制代码 <build>         <plugins>             <plugin>                 <groupId>org.codehaus.mojo</groupId>                 <artifactId>build-helper-maven-plugin</artifactId>                 <version>1.10</version>                 <executions>                     <execution>                         <phase>generate-sources</phase>                         <goals>                             <goal>add-source</goal>                         </goals>                         <configuration>                             <sources>                                 <source>${project.build.directory}/generated-sources/annotations</source>                             </sources>                         </configuration>                     </execution>                 </executions>             </plugin>         </plugins>     </build> 复制代码 编译时,Motan自动生成异步service类,生成路径为target/generated-sources/annotations/,生成的类名为service名加上Async,例如service类名为HelloWorldService.java,则自动生成的类名为HelloWorldServiceAsync.java。 另外,需要将motan自动生产类文件的路径配置为项目source path,可以使用maven plugin或手动配置,以上使用maven plugin方式。 这样,我们就能在eclipse中的source folder 中生成HelloWorldServiceAsync.java。 4.motan-client.xml配置的motan:referer标签中配置interface为自动生成的以Async为后缀的对应service类 <motan:referer id="helloWorldReferer" interface="com.motan.service.HelloWorldServiceAsync" directUrl="localhost:8002"/> 5.测试,先启动server,再启动client 复制代码 public class Server {     @SuppressWarnings({ "unused", "resource" })

01

Error filterStart错误问题的解决「建议收藏」

log4j:WARN No appenders could be found for logger (org.apache.commons.digester.D igester.sax). log4j:WARN Please initialize the log4j system properly. log4j:WARN No appenders could be found for logger (org.apache.commons.digester.D igester). log4j:WARN Please initialize the log4j system properly. 2008-5-21 8:37:05 org.apache.catalina.core.StandardContext start 严重: Error filterStart 2008-5-21 8:37:05 org.apache.catalina.core.StandardContext start 严重: Context [/portal] startup failed due to previous errors 2008-5-21 8:37:06 org.apache.coyote.http11.Http11BaseProtocol start 信息: Starting Coyote HTTP/1.1 on http-8080 2008-5-21 8:37:06 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 2008-5-21 8:37:06 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/32 config=null

01
领券