Java Thread - 2

来源:互联网 发布:网络胜利组漫画版权 编辑:程序博客网 时间:2024/05/20 16:40

 

 

 

package com;

public class Test implements Runnable {

    
public static void main(String[] args) {

    Test test 
= new Test();
    Thread thread 
= new Thread(test);
    thread.start();
    System.
out.println(System.currentTimeMillis());
//    try {
//        Thread.sleep(5000);
//    } catch (InterruptedException e) {
//        
//        e.printStackTrace();
//    }
    
//for (;;) 
    {
        System.
out.println(System.currentTimeMillis());
        System.
out.println(Thread.currentThread().getName() + " HaHa");
    }


    }


    
public void run() {
    
try {
        Thread.sleep(
5000);
    }
 catch (InterruptedException e) {
        
        e.printStackTrace();
    }

    
//for (;;) 
    {
        System.
out.println(Thread.currentThread().getName() + " ByeBye");
    }

    }


}

1211852076125
1211852076125
main HaHa
Thread-0 ByeBye

 

 

package com;

public class Test implements Runnable {

    
public static void main(String[] args) {

    Test test 
= new Test();
    Thread thread 
= new Thread(test);
    thread.start();
    System.
out.println(System.currentTimeMillis());
    
try {
        Thread.sleep(
5000);
    }
 catch (InterruptedException e) {
        
        e.printStackTrace();
    }

    
//for (;;) 
    {
        System.
out.println(System.currentTimeMillis());
        System.
out.println(Thread.currentThread().getName() + " HaHa");
    }


    }


    
public void run() {
//    try {
//        Thread.sleep(5000);
//    } catch (InterruptedException e) {
//        
//        e.printStackTrace();
//    }
    
//for (;;) 
    {
        System.
out.println(Thread.currentThread().getName() + " ByeBye");
    }

    }


}

1211852205906
Thread-0 ByeBye
1211852210906
main HaHa

 

package com;

public class Test implements Runnable {

    
public static void main(String[] args) {

    Test test 
= new Test();
    Thread thread 
= new Thread(test);
    thread.start();
    System.
out.println(System.currentTimeMillis());
    
try {
        Thread.sleep(
5000);
    }
 catch (InterruptedException e) {
        
        e.printStackTrace();
    }

    
//for (;;) 
    {
        System.
out.println(System.currentTimeMillis());
        System.
out.println(Thread.currentThread().getName() + " HaHa");
    }


    }


    
public void run() {
    
try {
        Thread.sleep(
5000);
    }
 catch (InterruptedException e) {
        
        e.printStackTrace();
    }

    
//for (;;) 
    {
        System.
out.println(Thread.currentThread().getName() + " ByeBye");
    }

    }


}

1211852246312
1211852251312
main HaHa
Thread-0 ByeBye

 

原创粉丝点击