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();
}
}
}
{
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();
}
}
}
相关文章推荐
- 持久化修改Android模拟器的system分区
- String 和StringBuffer,StringBuilder的区别
- POJ-2524-Ubiquitous Religions
- 游戏编程中的人工智能技术-扫雷机系列
- Codevs 1074 食物链 2001年NOI全国竞赛
- Android 模仿微信长按录音功能
- 数据结构实验之二叉树五:层序遍历
- JavaScript从0开始构思表情插件
- CentOS 下安装 Memcache
- Linux下登录Oracle命令行时删除键^H解决方法
- 简单工厂模式---(2)
- Python 命令行输出的颜色设置
- codeforces 554C Kyoya and Colored Balls 【组合数学+费马小定理】
- ARM学习笔记(一)
- js代码总报变量未定义的错
- 第3条:用私有构造器或者枚举类型强化Singleton属性
- Java中抽象类和接口的区别
- windows下修改系统音量
- redis 学习笔记一,安装配置
- day07_XML模块