2015. 1. 14. 19:56
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package Thread;

class ShowThread extends Thread{
    String threadName;
    public ShowThread(String name){
        threadName=name;
    }
    public void run(){
        for(int i=0;i<10;i++){
            System.out.println("안녕하세요."+threadName +"입니다");
            try {
                sleep(100);
            } catch (Exception e) {
                    e.printStackTrace();
            }
        }
    }
}

class Delay extends Thread{
    public void delay(){
        try{
            sleep(100);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }
}

===================


package Thread;

public class ThreadUnderstand{
    public static void main(String[] args){
        ShowThread st1=new ShowThread("st1 스레드");
        ShowThread st2=new ShowThread("std2 스레드");
        Delay s=new Delay();
       
        st1.start(); //start()를 실행하면 run()메소드가 동작하도록 내부적으로 코딩되어 있다
        st2.start();
       
        System.out.println("순착적인 출력물1");
        s.delay();  //너무 빨리 실행 되어 딜레이를 걸어줌
        System.out.println("출력물2");
        System.out.println("출력물3");
        System.out.println("출력물4");
       
    }
}



'Java' 카테고리의 다른 글

Collections : reverseOrder()  (0) 2015.01.14
Java Streams - Java Stream Introduction  (0) 2015.01.14
an usage of Vector  (0) 2015.01.14
basic Vector  (0) 2015.01.14
encapsulating  (0) 2015.01.13
Posted by af334