我有一个Jersey REST服务,其资源类调用服务类上的方法。在测试期间,我们注意到资源方法的“输入”日志语句与服务之间的延迟。这种延迟可能长达5分钟,但通常在2分钟范围内。偶尔,延迟时间最短(毫秒)。
这是我们班级的样子:
资源
@Stateless
@Path("/provision")
public class ProvisionResource
{
private final Logger logger = LoggerFactory.getLogger(ProvisionResource.class);
@EJB
private ProvisionService provisionService;
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/subscriber")
public SubscriberAccount querySubscriberAccount(
@QueryParam("accountNum") String accountNum)
{
logger.debug("Entering querySubscriberAccount()");
final SubscriberAccount account;
try
{
account = provisionService.querySubscriber(accountNum);
}
catch (IllegalArgumentException ex)
{
logger.error("Illegal argument while executing query for subscriber account",
ex);
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
catch (Exception ex)
{
logger.error("Unexpected exception while executing query for subscriber account",
ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
logger.debug("Exiting querySubscriberAccount()");
return account;
}
}
服务:
@Singleton
public class ProvisionService
{
private final Logger logger = LoggerFactory.getLogger(ProvisionService.class);
public SubscriberAccount querySubscriber(final String accountNum) throws IllegalArgumentException, Exception
{
logger.debug("Entering querySubscriber()");
if (null == accountNum)
{
throw new IllegalArgumentException("The argument {accountNum} must not be NULL");
}
SubscriberAccount subscriberAccount = null;
try
{
// do stuff to get subscriber account
}
catch (Exception ex)
{
throw new Exception("Caught exception querying {accountNum}=["
+ accountNum + "]", ex);
}
finally
{
logger.debug("Exiting querySubscriber()");
}
return subscriberAccount;
}
以下是我们日志中的一些示例,显示了我们输入方法的时间戳。
2012 Feb 07 15:31:06,303 MST [http-thread-pool-80(1)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:31:06,304 MST [http-thread-pool-80(1)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:35:06,359 MST [http-thread-pool-80(1)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:40:33,395 MST [http-thread-pool-80(1)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:34:06,345 MST [http-thread-pool-80(2)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:37:24,372 MST [http-thread-pool-80(2)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:33:06,332 MST [http-thread-pool-80(4)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:34:15,349 MST [http-thread-pool-80(4)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:37:24,371 MST [http-thread-pool-80(4)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:40:36,004 MST [http-thread-pool-80(4)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:32:06,317 MST [http-thread-pool-80(5)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:34:15,325 MST [http-thread-pool-80(5)] DEBUG my.package.ProvisionService - Entering querySubscriber()
2012 Feb 07 15:36:06,373 MST [http-thread-pool-80(5)] DEBUG my.package.ProvisionResource - Entering querySubscriberAccount()
2012 Feb 07 15:40:34,956 MST [http-thread-pool-80(5)] DEBUG my.package.ProvisionService - Entering querySubscriber()
如您所见,第一个在输入资源的querySubscriberAccount后几乎立即调用了服务中的querySubscriber方法。但是,后续调用Web服务需要大约1到5分钟。资源中确实没有任何事情可以阻止处理/调用服务。
Web服务部署在Glassfish 3.1.1中的Linux服务器上。
有没有人见过这样的事情?有关正在发生的事情的任何建议吗?
修改
再多一点信息......
部署Web服务战的域中部署了4个应用程序:
当我们禁用耳朵和“其他”war文件(仅启用Jersey war和测试servlet)时,延迟问题就会消失。我们重新启动了战争和耳朵,事情仍在继续及时作出反应。当我们重新部署Jersey webservice war(进行一些日志记录更改)时,延迟问题立即回来了。