
프로세스 : 쓰레드 = 공장 : 일꾼
실행 전 상태 -> 프로그램
실행 중인 프로그램 -> 프로세스(자원과 쓰레드로 구성)
멀티 프로세스 vs 멀티쓰레드
새로운 프로세스 생성보다 새로운 쓰레드 생성 비용이 더 적다
//Thread클래스를 상속
class MyThread extends Thread {
public void run() { 작업내용 }
}
public static void main(String[] args) {
MyThread th1 = new MyThread();
th1.start();
}
//Runnable 인터페이스를 구현
class MyRunner1 implements Runnable { 작업내용 }
public static void main(String[] args) {
MyRunner1 r = new MyRunner1();
Thread th2 = new Thread(r);
th2.start();
}
start는 메소드가 실행되기 위한 환경을 만들어주고 run을 실행시킨다.