changeset 57:a60ec7414931

merge
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Fri, 08 Jul 2011 18:07:07 +0900
parents b2604c5c6a25 (current diff) 9250cacee347 (diff)
children 39741f18b4f2 a240b19b66f0
files
diffstat 2 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/MultiThreadTee.java	Fri Jul 08 18:06:22 2011 +0900
+++ b/src/test/MultiThreadTee.java	Fri Jul 08 18:07:07 2011 +0900
@@ -1,17 +1,20 @@
 package test;
 
 import java.util.LinkedList;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
 
 public class MultiThreadTee {
 
 	static class Parent extends Thread {
-		LinkedList<SynchronousQueue<String>> clients = new LinkedList<SynchronousQueue<String>>();
+		LinkedList<BlockingQueue<String>> clients = new LinkedList<BlockingQueue<String>>();
 
 
-		SynchronousQueue<String> accept() {
+		BlockingQueue<String> accept() {
 
-			SynchronousQueue<String> s = new SynchronousQueue<String>();
+			// BlockingQueue<String> s = new  LinkedBlockingQueue<String>();
+			BlockingQueue<String> s = new  SynchronousQueue<String>();
 			clients.add(s);
 			
 			return s;
@@ -20,7 +23,7 @@
 		}
 
 		void put(String s) throws InterruptedException {
-			for (SynchronousQueue<String> queue : clients) {
+			for (BlockingQueue<String> queue : clients) {
 				queue.put(s);
 				
 			}
@@ -33,7 +36,7 @@
 	
 	static class Client extends Thread {
 		Parent p;
-		private SynchronousQueue<String> queue;
+		private BlockingQueue<String> queue;
 		
 		
 		
@@ -48,8 +51,14 @@
 			String item;
 //			while(!(item = queue.poll()).equals("") ) {
 			while(true) {
-				item = queue.poll();
-				if(item == null) continue;
+				try {
+					item = queue.take();
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					// System.out.println("wating");
+					continue;
+				}
+				// if(item == null) continue;
 				if(item.equals("")) return;
 				System.out.println(item);
 			}
--- a/src/test/MulticastQueue.java	Fri Jul 08 18:06:22 2011 +0900
+++ b/src/test/MulticastQueue.java	Fri Jul 08 18:07:07 2011 +0900
@@ -14,7 +14,6 @@
 		
 		Runnable type2 = new Runnable(){
 
-			@Override
 			public void run()
 			{
 				Client<String> client = queue.newClient();
@@ -34,7 +33,6 @@
 		
 		Runnable thread = new Runnable(){
 
-			@Override
 			public void run()
 			{
 				Client<String> client = queue.newClient();