Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 | 29 | 30 | 31 |
Tags
- 레디스
- 이벤트루프
- 동적계획법
- 자바의 정석
- github
- Spring Boot
- 게시판
- 정처기
- 캐시
- sqld
- 깃허브
- 분할정복
- document database
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- VMware
- 실행 컨텍스트
- 영속성 컨텍스트
- SQL
- 스프링 부트
- in-memory
- 정보처리기사
- 스프링부트
- 스프링 시큐리티
- spring security
- 호이스팅
- MongoDB
- 다이나믹프로그래밍
- Redis
- JPA
- NoSQL
Archives
- Today
- Total
FreeHand
병렬처리(Thread, Stream) 본문
public class Main {
public static void main(String[] args) {
// Thread 생성
MyThread1 t1 = new MyThread1();
Thread t2 = new Thread(new MyThread2());
// Thread 실행
t1.start();
t2.start();
}
}
// Thread 클래스 상속
class MyThread1 extends Thread {
public void run() {
for (int i=0; i<100; i++) {
System.out.println(this.getName()); // Thread-0
}
}
}
// Runnable 인터페이스 구현
class MyThread2 implements Runnable {
public void run() {
for (int i=0; i<100; i++) {
System.out.print(Thread.currentThread().getName() + " "); // Thread-1
}
}
}
Thread의 실행 순서는 OS의 스케줄러가 결정함. OS에 의존적임.
start()는 새로운 call stack을 생성하고 거기서 run()을 호출함. 쓰레드마다 개별 호출 스택을 갖게됨.
쓰레드는 사용자 쓰레드와 데몬 쓰레드로 나뉨. 실행중인 사용자 쓰레드가 없을 때 프로그램이 종료됨.