1 16 17 package org.objectweb.cjdbc.scenario.standalone.socket; 18 19 import java.io.BufferedInputStream ; 20 import java.io.IOException ; 21 import java.io.ObjectInputStream ; 22 import java.net.ServerSocket ; 23 import java.net.Socket ; 24 25 31 public class UTFServer implements Runnable 32 { 33 int serverPort = 7603; 34 35 ServerSocket serverSocket; 36 String hexa; 37 38 41 public void run() 42 { 43 try 44 { 45 serverSocket = new ServerSocket (serverPort); 46 Socket clientSocket = serverSocket.accept(); 47 48 ObjectInputStream in = new ObjectInputStream (clientSocket 49 .getInputStream()); 50 boolean useBufferedStream = in.readBoolean(); 51 if (useBufferedStream) 52 in = new ObjectInputStream (new BufferedInputStream (clientSocket 53 .getInputStream())); 54 55 boolean useWriteObject = in.readBoolean(); 56 boolean useGC = in.readBoolean(); 57 boolean useReset = in.readBoolean(); 58 int loop = in.readInt(); 59 60 System.out.println("Starting new test with:" 61 + clientSocket.getInetAddress().getHostName()); 62 System.out.println("useWriteObject:" + useWriteObject); 63 System.out.println("useGC:" + useGC); 64 System.out.println("useReset:" + useReset); 65 System.out.println("loop:" + loop); 66 System.gc(); 67 long freeStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); 68 System.out.println("Free Memory at start:" + (freeStart / 1024 / 1024) 69 + " MBytes."); 70 71 72 if (useWriteObject) 73 { 74 for (int i = 0; i < loop; i++) 75 { 76 hexa = (String ) in.readObject(); 77 if (useGC) 78 System.gc(); 79 if (useReset) 80 in.reset(); 81 } 82 } 83 else 84 { 85 for (int i = 0; i < loop; i++) 86 { 87 88 int size = in.readInt(); 89 byte[] bytes = new byte[size]; 90 in.readFully(bytes); 91 hexa = new String (bytes); 92 } 93 } 94 95 long freeEnd = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); 96 long usedMemory = (freeEnd - freeStart); 97 System.out.println("Free Memory at end:" + freeEnd / 1024 / 1024 98 + " MBytes"); 99 System.out.println("Used Memory:" + usedMemory / 1024 / 1024 + " MBytes"); 100 System.out.println("Ending test with:" 101 + clientSocket.getInetAddress().getHostName()); 102 103 } 104 catch (Exception e) 105 { 106 e.printStackTrace(); 108 } 109 finally 110 { 111 try 112 { 113 serverSocket.close(); 114 } 115 catch (IOException e1) 116 { 117 e1.printStackTrace(); 119 } 120 } 121 } 122 123 126 public String getHexa() 127 { 128 return hexa; 129 } 130 131 134 public int getServerPort() 135 { 136 return serverPort; 137 } 138 139 142 public void setServerPort(int serverPort) 143 { 144 this.serverPort = serverPort; 145 } 146 147 152 public static void main(String [] args) throws Exception 153 { 154 UTFServer sutf = new UTFServer(); 155 while (true) 156 { 157 sutf.run(); 158 } 159 } 160 } | Popular Tags |