- 浏览: 222239 次
- 性别:
- 来自: 海南海口
文章分类
- 全部博客 (114)
- java基础 (25)
- 设计模式 (6)
- css (1)
- js (2)
- jquery (5)
- flash as3.0 (3)
- lucene (2)
- tomcat (3)
- uml (0)
- struts2 (7)
- spring (0)
- sql (1)
- ejb3.0 (2)
- jbpm4 (1)
- webservices (1)
- linux (3)
- ajax (1)
- 面试 (1)
- flex (0)
- soa (0)
- oracle解锁 (5)
- 工具 (3)
- ext (3)
- 好的网址 (1)
- junit (2)
- jmx (2)
- encache (1)
- redis (1)
- 网站 (1)
- oracle重要的sql (1)
- web (3)
- hadoop (2)
- DB2 (1)
- ui (1)
- sybase (1)
- ue使用快捷键 (1)
- eclipse优化 (1)
- 前端优化用到的插件 (1)
- zookeeper (1)
- solr (1)
- hibernate (1)
- svn (1)
- resion (1)
- resin (1)
- maven (1)
- mysql (1)
- url (1)
- 通过HttpFileServer设置共享 可以通过http方式访问 (1)
- 非技术 (2)
- 营销 (1)
- ELK (3)
最新评论
-
it_xiaowu:
jqwerty_123 写道我的出同样的问题却是因为引入cxf ...
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Ma -
繁星水:
实验证明可用,最后补充一下,可以不需要 set Package ...
axis根据wsdl生成java客户端代码 -
qq_16699317:
qq_16699317 写道求一份源代码,感激不尽。。。多谢了 ...
java博客系统 -
qq_16699317:
求一份源代码,感激不尽。。。多谢了
java博客系统 -
jqwerty_123:
我的出同样的问题却是因为引入cxf的时候jcl-over-sl ...
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Ma
package cn.mytest;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @Description: 线程监控超时的工具类
* @author
* @date 2014-9-18 下午04:47:12
*/
public class ThreadWathcher extends Thread {
private static ThreadWathcher watcher;
/**
* 存放对应的线程跟开始执行的时间
*/
private HashMap<Thread, Long> threadBornTimeCollection;
/**
* 需要被中断的线程
*/
private ArrayList<Thread> toRemoveThreads;
/**
* 超时时间
*/
private long timeOutMills;
/**
* 间隔扫描时间
*/
private long periodMills;
private ThreadWathcher() {
/**
* 设置线程为守护线程 以致主线程停止的时候守护线程也自动终止
*/
this.setDaemon(true);
threadBornTimeCollection = new HashMap<Thread, Long>();
toRemoveThreads = new ArrayList<Thread>();
}
/**
* 配置的超时时间必须是间隔检测时间的倍数+3 比如超时时间是1000则 period应该是503
* @param timeout
* @param period
* @return
*/
public static ThreadWathcher getInstance(long timeout, long period) {
if (watcher == null) {
watcher = new ThreadWathcher();
watcher.timeOutMills = timeout;
watcher.periodMills = period;
}
return watcher;
}
public int register(Thread thread) {
threadBornTimeCollection.put(thread, System.currentTimeMillis());
return threadBornTimeCollection.size();
}
@Override
public void run() {
super.run();
while (true) {// 守护线程
try {
Thread.sleep(periodMills);// 每隔periodMills秒检查一次
for (Thread e : threadBornTimeCollection.keySet()) {// 遍历已经注册过超时处理的线程集合
if (Math.abs(threadBornTimeCollection.get(e)
- System.currentTimeMillis()) > timeOutMills
&& e.isAlive()) {// 超时
toRemoveThreads.add(e);// 添加到超時线程集合中
}
}
for (Thread e : toRemoveThreads) {// 遍历超时线程集合
threadBornTimeCollection.remove(e);// 从超时集合中移除
e.interrupt();// 中断超时线程
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (toRemoveThreads.size() > 0) {
System.out.println("清空超时线程集合");
toRemoveThreads.clear();// 清空超时线程集合
}
}
}
}
}
package cn.mytest;
import java.util.ArrayList;
import java.util.HashMap;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Begin here...");
ThreadWathcher wacher = ThreadWathcher.getInstance(1000, 503);
wacher.start();
Thread a = new Thread() {
@Override
public void run() {
super.run();
int n = 0;
try {
System.out.println("A线程执行中-----");
Thread.sleep(1100);
System.out.println("A线程执行完成.....");
/* while (n < 1 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread a..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
a.setName("a");
wacher.register(a);
a.start();
Thread b = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("B线程执行中-----");
Thread.sleep(900);
System.out.println("B线程执行完成.....");
/* while (n < 5 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread b..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
b.setName("b");
b.start();
wacher.register(b);
Thread c = new Thread() {
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("C线程执行中-----");
Thread.sleep(1200);
System.out.println("C线程执行完成.....");
/* while (n < 12 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread c..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
c.setName("c");
c.start();
wacher.register(c);
Thread d = new Thread() {
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("D线程执行中-----");
Thread.sleep(500);
System.out.println("D线程执行完成.....");
/* while (n < 15 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread d..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
d.setName("d");
d.start();
wacher.register(d);
}
}
import java.util.ArrayList;
import java.util.HashMap;
/**
* @Description: 线程监控超时的工具类
* @author
* @date 2014-9-18 下午04:47:12
*/
public class ThreadWathcher extends Thread {
private static ThreadWathcher watcher;
/**
* 存放对应的线程跟开始执行的时间
*/
private HashMap<Thread, Long> threadBornTimeCollection;
/**
* 需要被中断的线程
*/
private ArrayList<Thread> toRemoveThreads;
/**
* 超时时间
*/
private long timeOutMills;
/**
* 间隔扫描时间
*/
private long periodMills;
private ThreadWathcher() {
/**
* 设置线程为守护线程 以致主线程停止的时候守护线程也自动终止
*/
this.setDaemon(true);
threadBornTimeCollection = new HashMap<Thread, Long>();
toRemoveThreads = new ArrayList<Thread>();
}
/**
* 配置的超时时间必须是间隔检测时间的倍数+3 比如超时时间是1000则 period应该是503
* @param timeout
* @param period
* @return
*/
public static ThreadWathcher getInstance(long timeout, long period) {
if (watcher == null) {
watcher = new ThreadWathcher();
watcher.timeOutMills = timeout;
watcher.periodMills = period;
}
return watcher;
}
public int register(Thread thread) {
threadBornTimeCollection.put(thread, System.currentTimeMillis());
return threadBornTimeCollection.size();
}
@Override
public void run() {
super.run();
while (true) {// 守护线程
try {
Thread.sleep(periodMills);// 每隔periodMills秒检查一次
for (Thread e : threadBornTimeCollection.keySet()) {// 遍历已经注册过超时处理的线程集合
if (Math.abs(threadBornTimeCollection.get(e)
- System.currentTimeMillis()) > timeOutMills
&& e.isAlive()) {// 超时
toRemoveThreads.add(e);// 添加到超時线程集合中
}
}
for (Thread e : toRemoveThreads) {// 遍历超时线程集合
threadBornTimeCollection.remove(e);// 从超时集合中移除
e.interrupt();// 中断超时线程
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (toRemoveThreads.size() > 0) {
System.out.println("清空超时线程集合");
toRemoveThreads.clear();// 清空超时线程集合
}
}
}
}
}
package cn.mytest;
import java.util.ArrayList;
import java.util.HashMap;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Begin here...");
ThreadWathcher wacher = ThreadWathcher.getInstance(1000, 503);
wacher.start();
Thread a = new Thread() {
@Override
public void run() {
super.run();
int n = 0;
try {
System.out.println("A线程执行中-----");
Thread.sleep(1100);
System.out.println("A线程执行完成.....");
/* while (n < 1 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread a..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
a.setName("a");
wacher.register(a);
a.start();
Thread b = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("B线程执行中-----");
Thread.sleep(900);
System.out.println("B线程执行完成.....");
/* while (n < 5 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread b..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
b.setName("b");
b.start();
wacher.register(b);
Thread c = new Thread() {
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("C线程执行中-----");
Thread.sleep(1200);
System.out.println("C线程执行完成.....");
/* while (n < 12 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread c..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
c.setName("c");
c.start();
wacher.register(c);
Thread d = new Thread() {
public void run() {
// TODO Auto-generated method stub
super.run();
int n = 0;
try {
System.out.println("D线程执行中-----");
Thread.sleep(500);
System.out.println("D线程执行完成.....");
/* while (n < 15 && !Thread.interrupted()) {
Thread.sleep(1000);
n++;
System.out.println("In thread d..." + n);
} */
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("线程因超时被终止...线程名" + this.getName());
}
}
};
d.setName("d");
d.start();
wacher.register(d);
}
}
发表评论
-
java调用cmd不显示cmd窗口的
2014-07-11 09:34 1012cmd /c start /b fis release 加 ... -
hadoop的入门案例
2013-03-20 17:03 922http://www.cnblogs.com/xia520pi ... -
数据库字段内容的压缩算法
2013-03-08 14:34 1034package cn.ljz; import java. ... -
记录一下消息异步发送的一下框架
2013-02-03 19:02 884disruptor jgroups akka Activ ... -
eclipse中调试jvm内存溢出
2013-01-26 19:45 1277http://www.blogjava.net/rosen/a ... -
jvm退出之前清理工作
2013-01-24 23:25 804try { Runtime.getRu ... -
jvm内存泄露
2012-12-14 14:22 1019查看java内存泄露的办法 1:利用jdk自带的jps命令查看 ... -
Java获取当前运行方法的名称
2012-06-04 14:42 1462方法一:new Exception().getStackTra ... -
jdbc封装事务
2012-02-27 10:10 1115装载从这个网址过来的http://hi.baidu.com/g ... -
hashmap源码解析经典
2011-12-30 22:24 962http://www.java3z.com/cwbwebhom ... -
hashmap的遍历
2011-12-30 22:04 1007for(Iterator ite = map.entrySet ... -
axis根据wsdl生成java客户端代码
2011-12-24 16:30 14318先下载axis jar包:axis-bin-1_4.zip。下 ... -
eclipse设置编译路径
2011-12-24 15:40 1024ljzblog/WebRoot/WEB-INF/classes ... -
java反射判断数组
2011-12-17 19:52 1031if (c.isArray()) { String ca ... -
java方法参数注解
2011-12-03 21:46 16004package cn.ljz.annotation; i ... -
java获取项目路径
2011-08-16 09:19 609this.getClass().getClassLoader( ... -
CardLayout 简单实现Demo
2010-11-10 00:11 2450package cn.ljz.test; import ... -
java反射机制小小总结
2010-08-18 10:40 12391:动态语言就是在程序运行的过程当中,可以改变程序的结果和变量 ... -
java线程小小总结
2010-08-18 09:52 1051线程:简单的来说就是 ... -
java注解小总结
2010-08-18 09:46 18411:从jdk1.5以后就开始出现注解了,主要有@overrid ...
相关推荐
主要介绍了C#中的多线程超时处理实践方案,非常不错,具有参考借鉴价值,需要的朋友可以参考下
.net C#线程超时的解决方案,使用的时候在被调线程入口调用一下这个方法就可以。更多详细代码见附件 Report.RegisterThread(Report.GetCurrentWin32ThreadID(),Thread.CurrentThread); #region 获取当取线程的...
讲解有关Java中多线程运行时针对单个线程的执行超时监控机制,用于处理单个线程执行控制
作用:模仿线程池操作,管理多线程任务,超时,以及完成任务的回调。如果有bug自行处理,服务器挂机一天跑了三千万个线程投递没有出现什么异常。资源作者:。流云思水。资源界面:。资源下载:。
V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException 同上面的get功能一样,多了设置超时时间。参数timeout指定超时时间,uint指定时间的单位,在枚举类...
qtconcurrent 多线程并发处理应用demo。开发环境Qt5.9.4
基于boost::asio的http server3修改的echo服务器,有多线程,多侦听端口,超时处理等
1.下载进度条展示,支持暂停,停止功能 2.显示下载/剩余大小,剩余时间,下载速度 3.多线程下载,不阻塞界面线程 4.文件断点续传下载 5.下载请求超时的处理 环境VS2015 + win10 64位
C++封装类CWSocket(多线程 非阻塞)vc mfc 一般直接添加就可用,还有超时处理,强大。
.怎么删掉啊,这个demo有点问题 新的版本请见blog: blog.csdn.net/fuadam
多线程应该采用消息中心来交换数据,这样就规避了线程同步交互,等待,阻塞等等,全部是异步调用,全部是接收消息工作,然后产生消息,线程间没有耦合,消息中心有很多成熟的方案如RabbitMQ, Redis(里面有简单的...
1.资源简介:PyQt5中使用多线程模块QThread解决了PyQt5界面程序执行比较耗时操作时,程序卡顿出现的无响应以及界面输出无法实时显示的问题,采用线程池ThreadPoolExecutor解决了ping多个IP多任务耗时问题。...
大数据保存时会存在线程等待,只有全部保存后才能往下执行,使用线程委托任务让流程先走完,数据慢慢保存,提高页面响应速度
4)终止多线程程序的两种方式(轮询访问变量和interrupt方法) 23 四Concurrent包详解 25 1)Executor接口 25 2)ExecutorService接口 27 3)Callable对象 28 4)Executors工厂类 29 5)使用ExecutorService的例子 30 6)...
Awaitility 是多线程代码测试 DSL 框架,用于同步异步操作。测试异步系统很难,它不仅需要处理线程,超时和并发问题,代码测试意图也需在此类细节下隐藏。但 Awaitility 可让您简明传达对异步系统的期望,且操作...
###################################################################### 下面的程序是一个基于IO::Poll和threads多线程的Echo服务程序,### 在这个程序中实现了对于Dos方式攻击的防御以及对连接超时的处理#######...
并发一个函数,等待1s后向timeout写入数据,在select中如果1s之内有数据向其他channel写入则会顺利执行,如果没有,这是timeout写入了数据,则我们知道超时了。 实现代码: package main import fmt import time ...
result () # blocks until results are ready 以十秒的超时时间运行一个函数并处理错误。 from pebble import concurrentfrom concurrent . futures import TimeoutError@ concurrent . process
2、用于改动核心程序就可用于自己的功能,多线程控制模块已经测试好 3、保证有任务时启用的线程处于工作状态,完成任务的线程会自动分配的新的任务,不用等待其他线程 4、可以结束超时的任务,并且设定重试次数 5、...