Thread 클래스를 상속받아 thread 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class CreateThread2 { /* Thread클래스를 상속받은 하위 클래스를 통한 thread 생성 */ public static void main(String[] args) { //직접 클래스를 정의해 Thread 생성 Thread thread = new SubThread(); thread.start(); //익명 클래스로 Thread 생성 Thread thread2 = new Thread() { public void run() { System.out.println("Anonymous thread"); } }; thread2.start(); } public static class SubThread extends Thread { public void run() { //thread 실행시 실행될 부분 System.out.println("Thread 하위클래스로 생성"); } } } | cs |
'Java' 카테고리의 다른 글
[제너릭]와일드카드 타입 (0) | 2017.02.17 |
---|---|
[제너릭]제너릭 메소드 (0) | 2017.02.16 |
[제너릭] 제너릭과 비제너릭 비교 (0) | 2017.02.15 |
Runnable을 이용한 Thread 생성 방법들 (0) | 2017.01.25 |
멀티 스레드 개념 (0) | 2017.01.25 |