JAVA动态打开多个线程
来源:互联网 发布:中国网络女主播排名 编辑:程序博客网 时间:2024/06/06 02:24
//多线程保存在线数据
public boolean invokeThreadMethod(List list){
int num = 1000; //定 义每个线程执行的数据量
List thdList = null;
Thread thread = null;
boolean flag = false;
//根据数据量确定开多少个线程
int temp = list.size()/num;
int begin = 0;
int end = 0;
//判断数据量是否小于num
if(temp == 0){
thread = new Thread(new MyThread(list));
MyThread.threadList.add(thread);
thread.start();
}
//根据数据量动态打开多线程
for(int i=0;i<temp;i++){
begin = i*num;
if(i == (temp-1)){
end = list.size();
}else{
end = i*num+num;
}
thdList = new ArrayList();
for(int j=begin;j<end;j++){
thdList.add((Httz)list.get(j));
}
thread = new Thread(new MyThread(thdList));
MyThread.threadList.add(thread);
thread.start();
}
//判断所有线程是否都执行完毕
while (true) {
List<Thread> threadList = MyThread.threadList;
for(int i=0;i<threadList.size();i++){
if(!((Thread)threadList.get(i)).isAlive()){
threadList.remove(i);
}
}
if(threadList.size()==0){
flag = true;
break;
}
}
return flag;
}
public boolean invokeThreadMethod(List list){
int num = 1000; //定 义每个线程执行的数据量
List thdList = null;
Thread thread = null;
boolean flag = false;
//根据数据量确定开多少个线程
int temp = list.size()/num;
int begin = 0;
int end = 0;
//判断数据量是否小于num
if(temp == 0){
thread = new Thread(new MyThread(list));
MyThread.threadList.add(thread);
thread.start();
}
//根据数据量动态打开多线程
for(int i=0;i<temp;i++){
begin = i*num;
if(i == (temp-1)){
end = list.size();
}else{
end = i*num+num;
}
thdList = new ArrayList();
for(int j=begin;j<end;j++){
thdList.add((Httz)list.get(j));
}
thread = new Thread(new MyThread(thdList));
MyThread.threadList.add(thread);
thread.start();
}
//判断所有线程是否都执行完毕
while (true) {
List<Thread> threadList = MyThread.threadList;
for(int i=0;i<threadList.size();i++){
if(!((Thread)threadList.get(i)).isAlive()){
threadList.remove(i);
}
}
if(threadList.size()==0){
flag = true;
break;
}
}
return flag;
}
- JAVA动态打开多个线程
- java线程的多个状态
- java 多个线程之间错误处理
- java同时启动多个线程
- Java等待多个线程执行完毕
- java线程——多个线程之间切换执行
- Java动态生成excel表格,动态合并多个单元格
- 动态添加线程,然后监控多个线程是否都完成了
- 打开多个文件
- 打开多个idea
- 运行java线程后会有多少个线程
- 线程-多个线程多个锁
- 打开对话框打开多个文件
- Java实现监控多个线程状态的实现
- Java多线程下统计多个线程的运行时间
- java如何实现多个线程并发运行
- Java基础——多个线程共享数据
- JAVA 线程通信以及多个生产者消费者模型
- SQLite支持外键约束
- SSH执行存储过程
- Tomcate内存溢出解决方案
- 一致性哈希
- 一次艰难的ASP.NET生成Excel文件的历程总结
- JAVA动态打开多个线程
- 360度全景浏览代码,Xcode4.0编译,ios4.2
- Win7 64位下Visual Studio 2010连接Oracle数据库错误ORA-06413
- 使用internal(com.android.internal)和hidden(@hide)APIs
- NPOI实践: .NET导入Excel文件的另一种选择
- VC 打开目录对话框
- rt_mutex
- C++递归用法
- MTK 平台中,在11B平台生成moodis 多磁盘