여러 스레드가 같은 데이터에 접근하면 데이터 불일치 가능 → synchronized 같은 동기화 필요
+-----------------------+
| Process |
| |
| +-----------------+ |
| | Heap |<------- 모든 스레드가 공유하는 객체 메모리 공간
| +-----------------+ |
| |
| +-----------------+ |
| | Method Area |<------- 클래스 정보, static 변수 공유
| +-----------------+ |
| |
| +-----------------+ +-----------------+ +-----------------+
| | Thread 1 Stack | | Thread 2 Stack | | Thread 3 Stack |
| | (독립적 영역) | | (독립적 영역) | | (독립적 영역) |
| +-----------------+ +-----------------+ +-----------------+
| |
| PC Register (각 스레드별 실행 위치 저장)
| |
+-----------------------+
| Vector | ArrayList | |
|---|---|---|
| 동기화 | O | X |
| 성능 | 느림 | 빠름 |
| 멀티스레드 | 안전 | 동기화必 |
ArrayList<Integer> list = new ArrayList<>();
list.add(10); // 요소 추가
list.remove(0); // 인덱스 0의 요소 삭제
ArrayList<Integer> list = new ArrayList<>();
// 정수만 저장할 수 있는,
// 크기 조절이 가능한 배열(ArrayList)를 생성하고,
// 그 객체를 list이라는 이름으로 참조한다.
ArrayList list = new ArrayList();
list.add("문자열");
list.add(123); // 문자열, 숫자 모두 가능 -> 꺼낼 때 오류
ArrayList<Integer> list = new ArrayList<>();
list.add("문자열"); // 컴파일 에러
ArrayList list = new ArrayList();
// ArrayList<Integer> list = new ArrayList<>(); // 제네릭을 명시하면 타입 안정성 ↑
list.add(3);
list.add(3);
list.add(2);
HashSet set = new HashSet(list);
// HashSet<Integer> set = new HashSet<>(list);
// set = {3,2} 순서X,중복X
ArrayList list = new ArrayList();
list.add(3);
list.add(3);
list.add(2);
TreeSet tset = new TreeSet(list);
// TreeSet<Integer> tset = new TreeSet<>(list);
// tset = {2,3} 오름차순, 중복X
Stack stack = new Stack();
stack.addAll(
public interface Comparable<T> {
public int compareTo(T o);
//두 객체를 비교해서, 음수(작다)/0(같다)/양수(크다) 리턴
코드를 입력하세요