62,614
社区成员
发帖
与我相关
我的任务
分享
public void run() {
// List<AccessVo> vos = assess.get();
if (assess.size() == 0) {
return;
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
while (!isInterrupted()) {
for (AccessVo acs : assess) {
if (sdf.format(new Date()).equals(sdf.format(acs.getAccessTime()))) {
//通过Spring工具类,注入Service
managementService = (ManagementService) SpringApplicationContextHolder
.getSpringBean("managementService");
HttpTookit.doGet(acs.getUrl(), managementService);
}
}
try {
Thread.sleep(900);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
threadName = "monit" + targetId;
// 获取当前JVM所有线程
int flag = 0;
for (Thread thread : allThreads) {
// 如果存在就中断,重新创建一个线程
if (threadName.equals(thread.getName())) {
// thread.stop();// 中断此线程
// thread.join();
thread.interrupt();
DoAccessing newThread = new DoAccessing();
newThread.setAssess(vos);
Thread t = new Thread(newThread);
t.setName(threadName);
t.start();
flag++;
break;
}
}
if (flag == 0) {
// 没有则创建
DoAccessing newThread = new DoAccessing();
newThread.setAssess(vos);
Thread t = new Thread(newThread);
t.setName(threadName);
t.start();
}
} catch (Exception e) {
e.printStackTrace();
}