Java/Excercise

thread ch01 RunnableTest1

낭구리 2021. 9. 8. 18:11
package ch01;

import javax.swing.JFrame;

//Runnable 인터페이스를 구현하여 쓰레드 만들기 
class MyRunnable1 extends JFrame implements Runnable{

	@Override
	public void run() {
		for (int i = 0; i < 200; i++) {
			System.out.print(i + "\t");
		}
	}
}

public class RunnableTest1 {

	public static void main(String[] args) {

		MyRunnable1 myRunnable1 = new MyRunnable1();
		
		//사용방법
		//Runnable 구현한 객체는 Thread를 생성해서 매개 변수에 담고 쓰레드를 시작한다.(Start)
		
		Thread thread1 = new Thread(myRunnable1);
		thread1.start();
		Thread thread2 = new Thread(myRunnable1);
		thread2.start();
	}

}

'Java > Excercise' 카테고리의 다른 글

thread ch02 SharedResource  (0) 2021.09.08
thread ch01 RunnableTest2  (0) 2021.09.08
thread ch01 ThreadTest3  (0) 2021.09.08
swing ch04 집만들기  (0) 2021.09.07
thread ch01 MyThreadEx3  (0) 2021.09.07