일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 안드로이드 배경화면
- 안드로이드 개발 2.0
- 영어
- 스카이 안드로이드폰 시리우스
- 하루 한마디 영어
- 안드로이드 바탕화면
- 인기있는 블로그 만들기
- 안드로이드2.0
- 구글 안드로이드 개발
- 안드로이드개발
- 스마트폰 배경화면
- 아이폰 배경화면
- 안드로이드 개발 강좌
- 안드로이드2.0개발
- 스카이 안드로이드폰 시리우스 K양 동영상
- sky 시리우스폰
- 하루한마디영어
- MapView
- 구글 안드로이드
- 아이폰 바탕화면
- Form Stuff
- objective-c
- 안드로이드 2.0 개발
- 안드로이드
- SKY 시리우스
- android
- 구글안드로이드
- 안드로이드 개발 2.0 강좌
- 안드로이드 개발
- 안드로이드폰
- Today
- Total
moozi
자바쓰레드 동기화 관련예제 본문
class Process{
//동기화로 처리
public synchronized void process(){
for(int i=0;i<100;i++){
String ThreadName=Thread.currentThread().getName();
System.out.println(ThreadName+":"+i);
}
}
public void process2(){
for(int i=0;i<100;i++){
String ThreadName=Thread.currentThread().getName();
System.out.println("===="+ThreadName+":"+i);
}
}
}
//Runnable이 인터페이스이므로 추가로 다른 클래스 상속 가능.
class myThread implements Runnable{
Process proc;
public myThread(Process p){
this.proc=p;
}
public void run(){
proc.process();
proc.process2();
}
}
public class Thread03 {
public static void main(String[] args) {
//값을 증가시키는 작업을 담당하는 인스턴스 생성
Process proc=new Process();
Thread t =new Thread(new myThread(proc));
t.start();
Thread t2 =new Thread(new myThread(proc));
t2.start();
}
}