public void checkIPAuth(String iccid,String ipAddress)
{
AsyncIPAuth as = new AsyncIPAuth(iccid,ipAddress);
boolean isSucceed = false;
ThreadPoolManager poolManager = ThreadPoolManager.getInstance();
int recordCount = 0;
// 如果是线程池中的线程忙,则一直重试
while (!isSucceed)
{
try
{
poolManager.execute(as);
isSucceed = true;
}
catch (RejectedExecutionException ex)
{
isSucceed = false;
recordCount++;
if (recordCount >= PropertiesUtil.getValueInt(
"asyncDoActiveReTryCount", 2))
{
logger.error("pool busy....AsyncIPAuth failed!,as=" + as);
isSucceed = true;
}
try
{
Thread.sleep(1000L);
}
catch (Exception e)
{
logger.error("DeviceServiceImpl.AsyncIPAuth sleep error!",
e);
}
}
}
}
class AsyncIPAuth implements Runnable
{
private String iccid;
private String ipAddress;
/**
*
* @param iccid
* @param ipAddress
*/
public AsyncIPAuth(String iccid,String ipAddress)
{
this.iccid = iccid;
this.ipAddress = ipAddress;
}
@Override
public void run() {
String realIp = "";
String result = "";
if(!StringUtil.isNil(ipAddress) && ipAddress.length() == 8){
realIp = getIp(ipAddress);
}
StringBuilder sb = new StringBuilder();
String url = sb.append(PropertiesUtil.getValueString("EOC_UP_ONLINEBYIP_AUTH")).toString();
Map<String, String> map = new HashMap<String, String>();
map.put("operate", "1");
map.put("iccid", iccid);
if(!StringUtil.isNil(realIp)){
map.put("ip", realIp);
}
try {
result = RestUtil.getRestContent(url, map);
} catch (IOException e) {
e.printStackTrace();
}
}
}
{
AsyncIPAuth as = new AsyncIPAuth(iccid,ipAddress);
boolean isSucceed = false;
ThreadPoolManager poolManager = ThreadPoolManager.getInstance();
int recordCount = 0;
// 如果是线程池中的线程忙,则一直重试
while (!isSucceed)
{
try
{
poolManager.execute(as);
isSucceed = true;
}
catch (RejectedExecutionException ex)
{
isSucceed = false;
recordCount++;
if (recordCount >= PropertiesUtil.getValueInt(
"asyncDoActiveReTryCount", 2))
{
logger.error("pool busy....AsyncIPAuth failed!,as=" + as);
isSucceed = true;
}
try
{
Thread.sleep(1000L);
}
catch (Exception e)
{
logger.error("DeviceServiceImpl.AsyncIPAuth sleep error!",
e);
}
}
}
}
class AsyncIPAuth implements Runnable
{
private String iccid;
private String ipAddress;
/**
*
* @param iccid
* @param ipAddress
*/
public AsyncIPAuth(String iccid,String ipAddress)
{
this.iccid = iccid;
this.ipAddress = ipAddress;
}
@Override
public void run() {
String realIp = "";
String result = "";
if(!StringUtil.isNil(ipAddress) && ipAddress.length() == 8){
realIp = getIp(ipAddress);
}
StringBuilder sb = new StringBuilder();
String url = sb.append(PropertiesUtil.getValueString("EOC_UP_ONLINEBYIP_AUTH")).toString();
Map<String, String> map = new HashMap<String, String>();
map.put("operate", "1");
map.put("iccid", iccid);
if(!StringUtil.isNil(realIp)){
map.put("ip", realIp);
}
try {
result = RestUtil.getRestContent(url, map);
} catch (IOException e) {
e.printStackTrace();
}
}
}