멀티쓰레드 3

멀티쓰레드 프로그래밍 multi-thread programming

멀티쓰레드 프로그래밍 임계영역(critical section) - 두 개 이상의 thread가 동시에 접근하게 되는 리소스 - critical section에 동시에 thread가 접근하게 되면 실행 결과를 보장 할 수 없음 - thread간의 순서를 맞추는 동기화(synchronized)이 필요 동기화(synchronized) - 임계 영역에 여러 thread가 접근하는 경우 한 thread가 수행 하는 동안 공유 자원을 lock하려 다른 thread의 접근을 막음 - 동기화를 잘못 구현하면 deadlock에 빠질 수 있음 자바에서 동기화 구현 - synchronized수행문과 synchronized 메서드를 이용 1. synchronized 수행문 synchronized(참조형 수식){ } 참조형 수..

JAVA 2019.10.28

Thread class

Thread Process - 실행중인 프로그램 - OS로부터 메모리를 할당 받음 -> 메모리에 올라가서 할당된 상태에서 실행중인 프로그램 Thread - 실제 프로그램이 수행되는 작업의 최소 단위 - 하나의 프로세스는 하나 이상의 Thread를 가지게됨 -> 실행 단위 ■ Thread를 구현하는 방법 1. Thread를 extends 하는 방법 class Test{ t = new Thread(); t.start(); } class AnyThread extends Thread{ public void run(){ ....... } } 2. Runnable 인터페이스 구현 class Test{ t = new Thread(new Anything()); t.start(); } class AnyThread imp..

JAVA 2019.10.26

String 클래스

String은 immutable - 한번 선언되거나 생성된 문자열을 변경할 수 없음(불변성) - String 클래스의 concat() 메서드 혹은"+"을 이용하여 String을 연결하는 경우 문자열은 새로 생성됨 package string; public class StringTest2 { public static void main(String[] args) { String java = new String("java"); String android = new String("android"); System.out.println(System.identityHashCode(java)); java =java.concat(android); System.out.println(java); //새로운 생성된 문자열을 가..

JAVA 2019.10.05