【发布时间】:2014-03-03 03:31:17
【问题描述】:
我的英语不太好。先写代码。
@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
【问题讨论】:
-
userSignService是从哪里来的? -
公共接口 IUserSignService ;像这样实现:@Service public class UserSignServiceImpl extends BaseServiceImpl implements IUserSignService
-
很公平,但我看不到它在哪里声明或实例化。没有它,我们就没有合理的方式来回答这个问题。
-
@Autowired IUserSignService userSignService;
-
可能是慢速服务器的磁盘比其他的慢。删除所有记录调用(除了最后一个,它会显示总时间),看看它是否有区别。