您的位置:首页 > 其它

ThreadPoolManager

2016-07-26 10:31 375 查看
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();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: