달력

5

« 2024/5 »

  • 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
  • 31
2013. 1. 15. 17:41

BlockingQueue I.lib()/I.lib(Java)2013. 1. 15. 17:41

.. .. ..

3중 1번 클레스

package concurent;

import java.util.concurrent.*;

public class blockingQuere11 {
public static void main(String[] args) {
BlockingQueue<String> drop = new ArrayBlockingQueue(1, true);
(new Thread(new blockingQuere13(drop))).start();
(new Thread(new blockingQuere12(drop))).start();
}
}

3중 2번 클레스

package concurent;

import java.util.*;
import java.util.concurrent.*;

class blockingQuere12 implements Runnable{

private BlockingQueue<String> drop;

public blockingQuere12(BlockingQueue<String> d) {
this.drop = d; }

public void run(){
try{
String msg = null;

while (!((msg = drop.take()).equals("DONE")))
System.out.println("out : "+ System.currentTimeMillis() + msg);

}catch (InterruptedException intEx){
System.out.println("Interrupted! " + "Last one out, turn out the lights!");
}
}
}

3중 3클래스

package concurent;

import java.util.*;
import java.util.concurrent.*;

public class blockingQuere13 implements Runnable {

private BlockingQueue<String> drop;
List<String> messages = Arrays.asList("1111", "2222",
"3333", "44444","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25");

public blockingQuere13(BlockingQueue<String> d) {
this.drop = d;
}

public void run() {
try {
for (String s : messages){
drop.put(s);
System.out.println("i n : "+ System.currentTimeMillis() + s);
}
drop.put("DONE");
} catch (InterruptedException intEx) {
System.out.println("Interrupted! "+ "Last one out, turn out the lights!");
}
}
}

결과값

out : 13582386103091111
i n : 13582386103091111
out : 13582386103092222
i n : 13582386103092222
out : 13582386103093333
i n : 13582386103093333
out : 135823861030944444
i n : 135823861030944444
out : 13582386103095
i n : 13582386103095
out : 13582386103096
i n : 13582386103096
out : 13582386103107
i n : 13582386103107
out : 13582386103108
i n : 13582386103108
out : 13582386103109
i n : 13582386103109
out : 135823861031010
i n : 135823861031010
out : 135823861031011
i n : 135823861031011
out : 135823861031012
i n : 135823861031012
out : 135823861031013
i n : 135823861031013
out : 135823861031014
i n : 135823861031014
out : 135823861031015
i n : 135823861031015
out : 135823861031016
i n : 135823861031016
out : 135823861031017
i n : 135823861031017
out : 135823861031018
i n : 135823861031118
out : 135823861031119
i n : 135823861031119
out : 135823861031120
i n : 135823861031120
out : 135823861031121
i n : 135823861031121
out : 135823861031122
i n : 135823861031122
out : 135823861031123
i n : 135823861031123
out : 135823861031124
i n : 135823861031124
out : 135823861031125
i n : 135823861031125


.
:
Posted by .07274.