changeset 40:dd1321b67f95

sendReadData : newSingleThreadExecutor()
author e085711
date Mon, 06 Jun 2011 12:26:12 +0900
parents f399eec66846
children 37e287cfe7e0
files src/myVncProxy/MyRfbProto.java
diffstat 1 files changed, 17 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java	Sun Jun 05 22:30:46 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Mon Jun 06 12:26:12 2011 +0900
@@ -11,13 +11,13 @@
 import java.net.BindException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.nio.ByteBuffer;
 import java.util.LinkedList;
 
 import javax.imageio.ImageIO;
 
-import org.omg.CORBA.portable.OutputStream;
-
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.io.OutputStream;
 
 class MyRfbProto extends RfbProto {
 
@@ -39,6 +39,9 @@
 	private LinkedList <Thread> sendThreads;
 	boolean createBimgFlag;
 	
+	ExecutorService executor;
+	
+	
 	byte[] pngBytes;
 	
 	MyRfbProto(String h, int p, VncViewer v ) throws IOException {
@@ -47,6 +50,8 @@
 		cliListTmp = new LinkedList <Socket>();
 		createBimgFlag = false;
 		sendThreads = new LinkedList <Thread>();
+//		executor = Executors.newCachedThreadPool();
+		executor = Executors.newSingleThreadExecutor();
 	}
 
 	MyRfbProto(String h, int p) throws IOException {
@@ -55,6 +60,8 @@
 		cliListTmp = new LinkedList <Socket>();
 		createBimgFlag = false;
 		sendThreads = new LinkedList <Thread>();
+//		executor = Executors.newCachedThreadPool();
+		executor = Executors.newSingleThreadExecutor();
 	}
 
 	void initServSock(int port) throws IOException{
@@ -211,41 +218,23 @@
 		readFully(buffer);
 		sendData(buffer);
 	}
-	void readSendData()throws IOException {
+	void readSendData()throws IOException{
 		byte buffer[] = new byte[dataLen];
 		readFully(buffer);
 		reset();
 
-		LinkedList <Thread> threads;
-		threads = new LinkedList<Thread>();
-
 		for(Socket cli : cliList){
-//			try{
-//				OutputStream out = (OutputStream) cli.getOutputStream();
-//				Thread th = new Thread(new SendThread(out, buffer));
-				Thread th = new Thread(new SendThread(cli, buffer));
-				threads.add(th);
-/*
-		}catch(IOException e){
-				// if socket closed
+			try{
+				OutputStream out = cli.getOutputStream();
+				executor.execute(new SendThread(out, buffer));
+			}catch(IOException e){
+				// if client socket closed
 				cliListTmp.remove(cli);
 			}catch(Exception e){
 				
 			}
-*/	
-		}
-		
-		for(Thread thread : threads){
-			thread.start();
+
 		}
-		try{
-			for(Thread thread : threads){
-				thread.join();
-			}
-		}catch(InterruptedException e){
-			
-		}
-		
 	}
 	void regiFramebufferUpdate()throws IOException{
 		mark(20);