Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring mvc服务中调用方法花费太多时间_Java_Spring_Resin - Fatal编程技术网

Java 在Spring mvc服务中调用方法花费太多时间

Java 在Spring mvc服务中调用方法花费太多时间,java,spring,resin,Java,Spring,Resin,我的英语不太好。先编码 @ResponseBody @RequestMapping(value = "testcall") public UnifiedResponse testMethodCall( HttpServletRequest request, HttpServletResponse response) { UnifiedResponse unifiedResponse = new Unified

我的英语不太好。先编码

    @ResponseBody
    @RequestMapping(value = "testcall")
    public UnifiedResponse testMethodCall(
            HttpServletRequest request,
            HttpServletResponse response) {
        UnifiedResponse unifiedResponse = new UnifiedResponse();
        logger.info("t1:"+System.currentTimeMillis());
        Fun(0,1452,"abd",1);
        logger.info("t2:"+System.currentTimeMillis());
        userSignService.testcall();
        logger.info("t3:"+System.currentTimeMillis());

        return unifiedResponse;
    }


    String  Fun(int i,long l,String s,int ii){
        logger.info("f1:"+System.currentTimeMillis());
        return "";
    }
和日志输出:

 t1:1393816077311
 f1:1393816077312
 t2:1393816077312
 f2:1393816077345
 t3:1393816077410
testcall()
是服务中的一个方法,既没有参数也没有返回值。只需输出时间戳

服务的实现方式如下:

@Service
public class UserSignServiceImpl extends BaseServiceImpl implements IUserSignService {
 public void testcall() {
    logger.info("f1:"+System.currentTimeMillis());
 }

}
通过注释实例化

@Autowired
IUserSignService userSignService;
这只发生在某些服务器上。在其他服务器上,t3-t1小于2ms。所有服务器都使用相同版本的JDK和Resin

为什么?

调用方和方法之间的堆栈跟踪:

UserSignServiceImpl.testcall() line: 448    
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: 319 
ReflectiveMethodInvocation.invokeJoinpoint() line: 183  
ReflectiveMethodInvocation.proceed() line: 150  
TransactionInterceptor.invoke(MethodInvocation) line: 110   
ReflectiveMethodInvocation.proceed() line: 172  
ExposeInvocationInterceptor.invoke(MethodInvocation) line: 90   
ReflectiveMethodInvocation.proceed() line: 172  
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 202   
$Proxy49.testcall() line: not available 
OtherController.testMethodCall(HttpServletRequest, HttpServletResponse) line: 6329  

原因是拦截器。一旦我移除它,t3-t2下降到1ms。 org.springframework.orm.hibernate3.HibernateTransactionManager 包com.xxx.service中的所有方法都将触发此管理器。我不知道内部机制,但我猜可能是这样的: 更快的服务器进程在CPU中有12M的L3缓存,而较慢的服务器没有。服务方法在任何地方都被调用,使其成为最常用的方法。更快的服务器可能会缓存它,因此进程更快。
我不确定。还有什么解释吗?

userSignService是从哪里来的?公共接口IUserSignService;实现方式如下:@Service public class UserSignServiceImpl扩展了BaseServiceImpl实现的IUserSignServiceFair,但我看不到它在哪里声明或实例化。没有这些,我们就无法合理地回答这个问题。@autowirediusersignservice userSignService;可能速度慢的服务器的磁盘比其他服务器的磁盘慢。删除所有日志记录调用(最后一个除外,它将显示总时间),并查看它是否有影响。