package thread;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolDemo {
public static void main(String[] args){
long time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
Thread t = new Thread(new OneRunnable());
t.start();
}
long time2 = System.currentTimeMillis();
System.out.println("不使用线程池花费的时间是:"+(time2-time1));
ExecutorService pool = Executors.newFixedThreadPool(1000);
time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
pool.submit(new OneRunnable());
}
time2 = System.currentTimeMillis();
System.out.println("第一次使用线程池花费的时间是:"+(time2-time1));
time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
pool.submit(new OneRunnable());
}
time2 = System.currentTimeMillis();
System.out.println("再次使用线程池花费的时间是:"+(time2-time1));
pool.shutdown();
}
}能说一下改错的原理吗
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolDemo {
public static void main(String[] args){
long time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
Thread t = new Thread(new OneRunnable());
t.start();
}
long time2 = System.currentTimeMillis();
System.out.println("不使用线程池花费的时间是:"+(time2-time1));
ExecutorService pool = Executors.newFixedThreadPool(1000);
time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
pool.submit(new OneRunnable());
}
time2 = System.currentTimeMillis();
System.out.println("第一次使用线程池花费的时间是:"+(time2-time1));
time1 = System.currentTimeMillis();
for(int i=0;i<1000;i++){
pool.submit(new OneRunnable());
}
time2 = System.currentTimeMillis();
System.out.println("再次使用线程池花费的时间是:"+(time2-time1));
pool.shutdown();
}
}能说一下改错的原理吗
只是个测程序时间的代码~
说这行有错的
后面的new OneRunnable()就跟着错Exception in thread "main" java.lang.Error: Unresolved compilation problems:
OneRunnable cannot be resolved to a type
OneRunnable cannot be resolved to a type
OneRunnable cannot be resolved to a type
看一下这OneRunnable这个类是在那定义的??