在使用Java api对接路透系统,通过consumer.registerClient(xxx)发消息过程中,出现了死锁的问题,查看了ema的jar包源码,发现在ema对消息处理过程中对线程上了jdk的锁,没有释放该锁导致线程阻塞,从而导致容器崩溃,下面附上代码,还请帮忙解惑
try
{//args为ric和serviceName的映射关系
Iterable<Map.Entry<String,String>> it = args.entrySet().iterator;
while(it.hasNext()){
Map.Entry<String,String> entry = it.next();
List<String> list = Array.asList(entry.getValue().split(";"));
for(String ric : list){
consumer.registerClient( EmaFactory.createReqMsg().serviceName(entry.getKey()).name(ric), appClient, 0);
}
}
}
catch (OmmException excp)
{
System.out.println(excp.getMessage());
}
项目启动时创建appClient和ommConsumer
@Bean
public AppClient creatOmmconsumerClient(){
AppClient appClient = new AppClient();
return appClient;
}
@Bean
public OmmConsumer creatOmmConsumer(){
try{
OmmConsumerConfig config = EmaFactory.createOmmConsumerConfig();
OmmConsumer consumer = EmaFactory.createOmmConsumer(config.host(hostName).username(userName));
return consumer;
}catch (Exception e){
e.printStackTrace();
OmmConsumer consumer = new OmmConsumer() {
@Override
public String consumerName() {
return null;
}
@Override
public long registerClient(ReqMsg reqMsg, OmmConsumerClient client) {
return 0;
}
@Override
public long registerClient(ReqMsg reqMsg, OmmConsumerClient client, Object closure) {
return 0;
}
@Override
public long registerClient(ReqMsg reqMsg, OmmConsumerClient client, Object closure, long parentHandle) {
return 0;
}
@Override
public long registerClient(TunnelStreamRequest tunnelStreamRequest, OmmConsumerClient client) {
return 0;
}
@Override
public long registerClient(TunnelStreamRequest tunnelStreamRequest, OmmConsumerClient client, Object closure) {
return 0;
}
@Override
public void reissue(ReqMsg reqMsg, long handle) {
}
@Override
public void submit(GenericMsg genericMsg, long handle) {
}
@Override
public void submit(PostMsg postMsg, long handle) {
}
@Override
public long dispatch() {
return 0;
}
@Override
public long dispatch(long timeOut) {
return 0;
}
@Override
public void unregister(long handle) {
}
@Override
public void uninitialize() {
}
@Override
public void channelInformation(ChannelInformation ci) {
}
@Override
public void modifyIOCtl(int code, int value) {
}
@Override
public void renewOAuthCredentials(OAuth2CredentialRenewal credentials) {
}
}
}
}
ema报错的代码如下标粗斜体;异常捕获如上图
protected long registerClient(ReqMsg reqMsg, T client, Object closure)
{
if(checkClient(client))
return 0;
try
{
_userLock.lock();
long handle = _itemCallbackClient != null ? _itemCallbackClient.registerClient(reqMsg, client, closure, 0) : 0;
return handle;
}
finally
{
_userLock.unlock();
}
}