1、修复dc数据库连接没有释放的bug

2、socket server 添加连接client限制,防止同时多个client连接导致dc程序不能正常运行的问题
This commit is contained in:
fangshunjian
2018-11-21 13:26:37 +08:00
parent ba43f4203d
commit e0737f8a42
6 changed files with 90 additions and 33 deletions

View File

@@ -24,7 +24,7 @@ public abstract class SSLSocketCallable extends SocketUtils implements Callable<
private static Logger logger = Logger.getLogger(SSLSocketCallable.class);
//ServerSocket 通讯服务
protected SSLServerSocket ss = null;
private boolean clientFlag = false;// 是否dc server 接收的client
/**
* 通讯创建
* @param ip 目标主机IP
@@ -41,6 +41,7 @@ public abstract class SSLSocketCallable extends SocketUtils implements Callable<
*/
public SSLSocketCallable(Socket client) {
super(client);
clientFlag = true;
}
/**
@@ -51,39 +52,39 @@ public abstract class SSLSocketCallable extends SocketUtils implements Callable<
public Object call(){
Thread.currentThread().setName("Create communication"+ip+":"+port);
Object obj = null; //返回对象
try {
try {
//- 校验 是否创建新通讯连接
if(socket==null){ //客户端通讯创建
createClientSocket();
}else{ //服务端通讯创建
createServerSocket();
}
} catch (SocketException e) {
logger.error("Create failed"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_CREATE_SOCKET,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
close();
return obj;
} catch (Exception e) {
close();
return obj;
}
//- 校验 是否创建新通讯连接
if(socket==null){ //客户端通讯创建
createClientSocket();
}else{ //服务端通讯创建
createServerSocket();
//-- 自定义通讯操作
try {
obj = toDo();
}catch (Exception e) {
logger.error("Communicate contents exception"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_SOCKET_RUNTIME,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
} finally {
close();
}
} catch (SocketException e) {
logger.error("Create failed"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_CREATE_SOCKET,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
close();
return obj;
} catch (IOException e) {
close();
return obj;
}catch (Exception e) {
close();
return obj;
}
//-- 自定义通讯操作
try {
obj = toDo();
}catch (Exception e) {
logger.error("Communicate contents exception"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_SOCKET_RUNTIME,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
} finally {
close();
if(clientFlag){
Common.releaseServerSemaphore();//释放server信号量
}
}
return obj;
}