Java 스레드

Jmnote (토론 | 기여)님의 2021년 10월 16일 (토) 15:47 판

1 개요

Java thread
Java 스레드, Java 쓰레드

2 Thread 상속

public class Main {
    public static void main(String[] args) {
        System.out.println("[main] started.");
        MyThread myThread = new MyThread();
        myThread.start();
        System.out.println("[main] finished.");
    }
}

class MyThread extends Thread {
    public void run() {
        System.out.println("MyThread is running.");
    }
}

3 Runnable 상속

public class Main {
    public static void main(String[] args) {
        System.out.println("[main] started.");
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        thread.start();
        System.out.println("[main] finished.");
    }
}

class MyRunnable implements Runnable {
    public void run() {
        System.out.println("MyRunnable is running.");
    }
}

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}