일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- sql
- orcle
- 주말이다..
- CSS
- html
- 코딩
- 테이블
- ERWin
- 웹
- 프로그래밍
- javascript
- 객체지향
- 공부
- DB
- 오라클
- UI
- 데이터베이스
- squery
- 객체지향프로그래밍
- 자바
- 웹프로그래밍
- Oracle
- Project
- web
- 객제지향
- 프로젝트
- 객제지향프로그래밍
- jsp
- Java
- 공부를열심히
Archives
- Today
- Total
햄찌개
JAVA - 쓰레드 -syncCollection 본문
* Vector, Hashtable등 예전부터 존재하던 Collection 클래스들은 내부에 동기화 처리가 되어 있다.
* 그런데, 최근에 새로 구성된 Collection들은 동기화 처리가 되어있지 않다.
* 그래서 동기화가 필요한 프로그램에서 이런 Collection들을 사용하려면
* 동기화 처리를 한 후 에 사용해야한다.
public class T18_SyncCollectionTest {
//동기화 처리를 하지 않을 경우..
private static List<Integer> List1 = new ArrayList<Integer>();
public static void main(String[] args) {
//익명 클래스로 쓰레드 구현
Runnable r = new Runnable() {
@Override
public void run() {
for (int i = 1; i <= 10000; i++) {
List1.add(i); //동기화 처리를 하지 않는 리스트 사용
}
}
};
Thread[] ths = new Thread[] {
new Thread(r),
new Thread(r),
new Thread(r),
new Thread(r),
new Thread(r)
};
long startTime = System.currentTimeMillis();
for (Thread th : ths) {
th.start();
}
for (Thread th : ths) {
try {
th.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println("처리 시간(ms)"+(endTime-startTime));
System.out.println("list1의 개수 :"+List1.size());
}
}
'고급 JAVA' 카테고리의 다른 글
JAVA -IO -File (0) | 2020.09.24 |
---|---|
JAVA - 쓰레드 - wait(), notify() (0) | 2020.09.24 |
JAVA - 쓰레드 예제 - 은행 입출금 - Lock (0) | 2020.09.23 |
JAVA - 쓰레드 예제 - 은행 입출금 -synchronized (0) | 2020.09.23 |
JAVA - 쓰레드 synchronized 동기화 (0) | 2020.09.23 |