참치코더의 꿈 메모장

Java 스레드(Thread) 생성 방법 본문

JAVA

Java 스레드(Thread) 생성 방법

참치깡 2025. 5. 6. 16:39
728x90
Thread 클래스로부터 직접 생성 방법 Thread 하위 클래스로부터 생성
1. class threadEx1 implements Runnable{
       public void run(){
                 // 스레드가 실행할 코드 부분;
         }
   }

2. Runnable example = new threadEx1();
    Thread thread = new Thread(example);
   

3. thread.run(); //스레드 실행

1. public class threadEx2 extends Thread{
        @override
         public void run(){
                    //스레드가 실행할 코드 부분; 
      }
}

2. Thread thread = new Thread();


3. thread.run(); // 스레드 실행
1. Thread thread = new Thread(new Runnable(){
       public void run(){
                // 스레드가 실행할 코드 부분;
               // 익명객체 활용
       }
} );

2. thread.run(); // 스레드 실행
1. Thread thread = new Thread(){
        public void run(){
               // 스레드가 실행할 코드 부분;
              // 익명객체 활용 
     }
};

2. thread.run(); // 스레드 실행

 

 

나고야 있을때 찍은 담장에 핀 예쁜 꽃

728x90
Comments