package com.zhicheng;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class Tread01 extends Thread {
long start1 = System.currentTimeMillis();
int count1 = 0;
public void fun1() {
for(int i = 0 ; i < 1000000; i++) {
Math.random();
}
}
public void run() {
System.out.println("start1"+start1);
while(true) {
long end1 = System.currentTimeMillis();
fun1();
count1++;
if ((end1 - start1) > 3000) {
System.out.println("end1"+end1+"差值:"+(end1-start1));
System.out.println("count1:"+count1);
break;
}
//Thread.sleep(5000);
}
}
}
class Tread02 extends Thread {
int count2 = 0;
long start2 = System.currentTimeMillis();
public void fun2(){
for(int i = 0 ; i < 10000; i++) {
Math.random();
}
}
public void run() {
System.out.println("start2"+start2);
while(true) {
fun2();
count2++;
long end2 = System.currentTimeMillis();
if ((end2 - start2) > 3000 ) {
System.out.println("end2"+end2+"差值:"+(end2-start2));
System.out.println("count2:"+count2);
break;
}
//Thread.sleep(7000);
}
/*try {
for (int i = 0; i < 60; i++) {
Thread.sleep(1000);
System.out.println("Thread02执行");
}
Thread.sleep(1000);
System.out.println("Thread02执行");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
}
public class MyThread01 {
public static void main(String[] args) {
Tread01 tread01 = new Tread01();
Tread02 tread02 = new Tread02();
tread01.start();
tread02.start();
/*long start = System.currentTimeMillis();
System.out.println("当前时间" + " " + start);
ExecutorService executor = Executors.newFixedThreadPool(2);
executor.execute(new Tread01());
executor.execute(new Tread02());
executor.shutdown();
while (!executor.isTerminated()) {
}
;
long end = System.currentTimeMillis();
System.out.println("\n当前时间" + " " + end);
System.out.println("\n用时" + " " + (end - start) / 1000 + "秒");*/
}
}