线程池
来源:互联网 发布:软件开发费用明细 编辑:程序博客网 时间:2024/06/06 08:51
public class ThreadPoolRunnable implements Runnable{
@Override
public void run() {
for(int i=1;i<=10;i++){
System.out.println(Thread.currentThread().getName()+" is looping of "+i);
}
}
}
//*****************************************************
package com.ygl;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolTest {
public static void main(String[] args) {
// ThreadPoolRunnable threadPoolRunnable=new ThreadPoolRunnable();
ExecutorService threadPool= Executors.newFixedThreadPool(3);//创建3个线程
for(int i=1;i<=10;i++){
//System.out.println("Task: "+i+"===============");
threadPool.execute(new ThreadPoolRunnable());
}
System.out.println("all task commit");
threadPool.shutdown();
}
}
//*************************************************************
package com.ygl;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolTest {
public static void main(String[] args) {
// ThreadPoolRunnable threadPoolRunnable=new ThreadPoolRunnable();
ExecutorService threadPool= Executors.newCachedThreadPool();//根据任务动态创建线程
for(int i=1;i<=10;i++){
//System.out.println("Task: "+i+"===============");
threadPool.execute(new ThreadPoolRunnable());
}
System.out.println("all task commit");
threadPool.shutdown();
}
}
//************************************************************
package com.ygl;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class ThreadPoolTest {
public static void main(String[] args) {
// ThreadPoolRunnable threadPoolRunnable=new ThreadPoolRunnable();
ExecutorService threadPool= Executors.newCachedThreadPool();//创建3个线程
for(int i=1;i<=10;i++){
//System.out.println("Task: "+i+"===============");
threadPool.execute(new ThreadPoolRunnable());
}
System.out.println("all task commit");
threadPool.shutdown();
//定时任务调度
Executors.newScheduledThreadPool(3).schedule(new ThreadPoolRunnable(),10,TimeUnit.SECONDS);
Executors.newScheduledThreadPool(3).scheduleAtFixedRate(new ThreadPoolRunnable(),10,2,TimeUnit.SECONDS);//10s后炸,每隔2s触发一次
}
}
- 线程与线程池
- 线程池 线程优先级
- Executor线程,线程池
- 线程、多线程、线程池
- IOS-线程、线程池
- Java线程:线程池
- 线程和线程池
- 线程、多线程、线程池
- 线程、多线程、线程池
- 线程(六)线程池
- ExecutorService(线程池)+线程
- 线程和线程池
- 线程&线程池 简略
- 线程和线程池
- 线程池 线程锁
- 线程、线程池总结
- 线程与线程池
- 线程、锁、线程池
- boost timer库使用
- 图像哈希检索背景综述(一)
- 线性回归及其Python实现(最大似然法)
- 递归练习二
- qt发布
- 线程池
- 010SK: 数据库无法设置连接选项 SET_READONLY_TRUE
- 关于代码重构:是微修还是全部推倒重来
- Bochs调试指令
- RecyclerView的基本用法
- ### Android 判断app的状态 重启app
- [Swift开发实战]-类的使用02
- 我的第一份工作
- linux wget下载java jdk