GGYU

thread 사용법 본문

프로그래밍/JAVA

thread 사용법

GANADARA 2018. 7. 19. 21:28


public class Test implements Runnable { int seq; public Test(int seq) { this.seq = seq; } public void run() { System.out.println(this.seq+" thread start."); try { Thread.sleep(1000); }catch(Exception e) { } System.out.println(this.seq+" thread end."); } public static void main(String[] args) { ArrayList<Thread> threads = new ArrayList<Thread>(); for(int i=0; i<10; i++) { Thread t = new Thread(new Test(i)); t.start(); threads.add(t); } for(int i=0; i<threads.size(); i++) { Thread t = threads.get(i); try { t.join(); }catch(Exception e) { } } System.out.println("main end."); } }

'프로그래밍 > JAVA' 카테고리의 다른 글

서버/클라이언트 예제  (0) 2018.07.19
크리티컬섹션 처리  (0) 2018.07.19
threadpool 사용법  (0) 2018.07.19
디렉토리 조회  (0) 2018.07.19
Input/OutputStream  (0) 2018.07.19
Comments