"자바 Runnable"의 두 판 사이의 차이

(새 문서: ==개요== ;Java Runnable ;자바 Runnable <syntaxhighlight lang='java' line run> public class Main { public static void main(String[] args) { System.out.println("[main]...)
 
3번째 줄: 3번째 줄:
;자바 Runnable
;자바 Runnable


==지명 Runnable==
<syntaxhighlight lang='java' line run>
<syntaxhighlight lang='java' line run>
public class Main {
public class Main {
17번째 줄: 18번째 줄:
     public void run() {
     public void run() {
         System.out.println("MyRunnable is running.");
         System.out.println("MyRunnable is running.");
    }
}
</syntaxhighlight>
==익명 Runnable==
<syntaxhighlight lang='java' line run>
public class Main {
    public static void main(String[] args) {
        System.out.println("[main] started.");
        Runnable runnable = new Runnable() {
            public void run() {
                System.out.println("MyRunnable is running.");
            }
                };
        Thread thread = new Thread(runnable);
        thread.start();
        System.out.println("[main] finished.");
     }
     }
}
}

2021년 10월 16일 (토) 15:57 판

1 개요

Java Runnable
자바 Runnable

2 지명 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.");
    }
}

3 익명 Runnable

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

4 같이 보기

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