'Thread'에 해당되는 글 2건

  1. 2014.07.09 쓰레드.. wait, notify, notifyAll
  2. 2014.07.09 Thread join 함수

wait, notify, notifyAll함수는 Object클래스에서 구현된 메소드이다.

당연히 모든 클래스가 다 상속받는 메소드이기도 하다.
사용법은 현재 자신클래스를 공유해서 사용하는 경우, 어떤 조건에 따라 자기를 사용하는 쓰레드를 대기시킬 경우 wait를 사용하고 자신이 다시 사용가능하게 될 경우 notify 또는 notifyAll을 호출한다. notify는 자신을 사용하려고 대기하는 쓰레드 중 아무거나 한개를 깨우고 notifyAll은 자신을 사용하려고 대기하는 쓰레드를 모두 다 깨운다.

notifyAll을 사용할 경우 wait를 사용하는 메소드에서 while문으로 wait를 사용해야 한다.



참조..

http://gladtosee.tistory.com/191


'java' 카테고리의 다른 글

maven build 할때 mapper.xml 누락되는 현상  (0) 2015.03.05
spring mysql datasouce  (0) 2015.02.08
Thread join 함수  (0) 2014.07.09
Spring - IoC & DI & AOP ( 퍼옴 )  (0) 2014.07.03
java 예외(exception) 처리에 대한 괜찮은 글..  (0) 2014.06.26
Posted by 무세1
,

Thread join 함수

java 2014. 7. 9. 20:25

쓰레드 실행할때..  쓰레드가 끝날때까지 기다려 주는 join 함수가 있다..


public class Counter extends Thread {

int a;

int b;

int sum;

Counter(int x, int y) {

a=x;

b=y;

}

public void run() {

for(int i=a; i<=b; i++) {

sumsum+i;

}

}

int getSum() {

return sum;

}

}


public class test01 {


public static void main(String[] args) throws InterruptedException {

Counter at = new Counter(0, 100);

System.out.println(at.isAlive());

at.start();

System.out.println(at.isAlive());

at.join();

//Thread.sleep(1);

System.out.println(at.getSum());

System.out.println(at.isAlive());

}

}


결과는...

false

true

5050

false



'java' 카테고리의 다른 글

spring mysql datasouce  (0) 2015.02.08
쓰레드.. wait, notify, notifyAll  (0) 2014.07.09
Spring - IoC & DI & AOP ( 퍼옴 )  (0) 2014.07.03
java 예외(exception) 처리에 대한 괜찮은 글..  (0) 2014.06.26
lamda.. (업데이트중)  (0) 2014.05.21
Posted by 무세1
,