连接池参数合并

This commit is contained in:
cheney 2022-08-05 18:47:20 +08:00
parent dc7f4e67ba
commit c9726dcd59
2 changed files with 28 additions and 10 deletions

View File

@ -13,9 +13,11 @@ import java.util.List;
public class SydApi4Database implements SydApi {
private SydApi4j[] hsms = null;
private boolean isShortLinkMode = false;
@Deprecated
public SydApi4Database() {
isShortLinkMode = true;
}
public SydApi4Database(SydApi4j[] hsms) {
@ -25,20 +27,23 @@ public class SydApi4Database implements SydApi {
@Override
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
hsms = new SydApi4j[]{ api };
hsms = new SydApi4j[]{api};
return this;
}
@Override
public void SYD_Disconnect_Ex() {
if (isShortLinkMode) {
SydApi4j api = hsms[0];
if (null != api) {
try {
api.disconnect();
} catch (Exception e) {
}
}
api = null;
}
// 配合链接池不再需要释放
// if ( null != api ) {
// try {
// api.disconnect();
// }catch ( Exception e ){
// }
// }
// api = null;
}
@Override

View File

@ -42,12 +42,25 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
// 保活接口
protected boolean check(SydApi o) {
null != o;
if ( null == o ) {
return false;
}
try {
o.SYD_SM3_Hash_ShortData( new byte[8] );
return true;
}catch ( Exception e) {
// 忽略
return false;
}
}
// 释放
protected void free(SydApi o) {
if ( null != o ) {
o.SYD_Disconnect_Ex();
}
}
}