本帖最后由 oath 于 2013-8-17 07:16 编辑
- package test;
- abstract class Temple{
-
- public void getTime(){
- long start = System.currentTimeMillis();
- System.out.println("程序开始时间:" + start);
-
- runcode();
-
- long end = System.currentTimeMillis();
- System.out.println("程序结束时间:"+end);
-
- System.out.println("程序用时:"+(end-start));
- }
- abstract void runcode() ;
- }
- class SaleTicket implements Runnable{
-
- public void run(){
- int ticket = 1000;
- for (int i = 0; i < 1000; i++) {
- if( ticket > 0 ) {
- System.out.println(Thread.currentThread().getName()+": "+ticket--);
- }
- }
- }
- }
- class Temple_Thread extends Temple{
- @Override
- void runcode() {
- // TODO Auto-generated method stub
-
- SaleTicket st = new SaleTicket();
-
- Thread t1 = new Thread(st,"one");
- Thread t2 = new Thread(st,"two");
- Thread t3 = new Thread(st,"third");
- t1.start();
- t2.start();
- t3.start();
- }
- }
- class test{
- public static void main(String[] args) {
- new Temple_Thread().getTime();
- }
- }
复制代码 上面的程序,多次测试,结果程序运行时间都为0,不应该啊……
大家帮我看看哪里写错了
|