2014-03-03 30 views
0

我的英文不太好。先編碼。春季mvc服務費用調用方法太多時間

@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 
+0

'userSignService'甚至來自哪裏? – Makoto

+0

public interface IUserSignService;執行如下:@Service public class UserSignServiceImpl extends BaseServiceImpl implements IUserSignService – user3373353

+0

公平的,但我不知道它在哪裏聲明或實例化。沒有這個,我們無法回答這個問題。 – Makoto

回答

0

原因是攔截。一旦我將其刪除,t3-t2降至1ms。 org.springframework.orm.hibernate3.HibernateTransactionManager 包com.xxx.service中的所有方法都會觸發這個manager.I不知道內部機制,但我猜可能是這樣的: 服務器進程更快有12M L3緩存在CPU中,較慢的一個沒有。服務方法被調用到處,使其成爲最常用的。更快的服務器可能緩存它,因此處理更快。 我不確定。還有其他解釋嗎?