我的程序是这样的,实现SOCKET 通信的服务器端:但测试时运行几十次就顿住了,重新开起这个程序也不行,必须重新启动系统,才行。对不起,分不够了!
import java.net.*; 
import java.io.*; 
import java.lang.*; 
import com.intel.fum.pull.*;
import com.intel.fum.common.Processor;
public class ceshi extends Thread{
Socket socket1;
String address;
public ceshi(Socket s){
socket1=s;
start();
}

public void run(){
try{
InputStream in=new BufferedInputStream(socket1.getInputStream());
//OutputStream out=new BufferedOutputStream(socket1.getOutputStream());
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true);
 String address=socket1.getInetAddress().getHostAddress();
while(true){
int n=in.available();
byte[]b=new byte[n];
if(n>0){
int result=in.read(b);
if(result==-1)
{
break;
}
    
  Processor Pro = new Processor();
byte[] a =Pro.queryUpgrade(b,address);
  
  int h=a.length;
    byte[] buf=new byte[h+2];
    buf[0]=(byte)2;
    buf[1]=(byte)(h+2);int m;int w;
    for(m=0,w=2;m<h&&w<h+2;m++,w++)
    {
     buf[w]=a[m];
    } for(int i=0;i<h+2;i++)
{

System.out.println(buf[i]);
}String s=new String(buf);
out.println(s);
out.close();
System.out.println(s); }
try{
                                 Thread.sleep(10);
                             }
                              catch(InterruptedException e)
                             {}
}
in.close();
} catch(IOException e){
System.err.println("catch"+e.getMessage());
}
finally{
try{
socket1.close();
}
catch(IOException e){
System.err.println("Socket not closed");
}
}
}
public static void main(String[] args)throws IOException{ 
ServerSocket s; 
s=new ServerSocket(2222); 
try{
         while(true){
                          Socket socket1=s.accept();                           try{
                          new ceshi(socket1);
                        }                        catch(Exception e){
                     socket1.close();
                                             }
                           try{
                                 Thread.sleep(10);
                             }
                              catch(InterruptedException e)
                             {} 
    }
    }finally{
s.close();
}}
}

解决方案 »

  1.   

    我说错了,是ORACLE数据库死掉了,得重新打开
      

  2.   

    TO troyzhang(troyzhang):
    设置最大连接数,是说连接池最大连接数吗?
      

  3.   

    谢谢!我修改了后,现在数据库不会死了,public class teshi extends Thread{
    Socket socket1;
    String address;
    InputStream in;
    PrintWriter out;
    static int i=0;
    public teshi(Socket s) throws IOException{
    socket1=s;
     in=new BufferedInputStream(socket1.getInputStream());
    //OutputStream out=new BufferedOutputStream(socket1.getOutputStream());
      out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true);
    start();
    }

    public void run(){
    try{
    //InputStream in=new BufferedInputStream(socket1.getInputStream());
    //OutputStream out=new BufferedOutputStream(socket1.getOutputStream());
    //PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true);

     String address=socket1.getInetAddress().getHostAddress();
    while(true){
    int n=in.available();

    if(n>0){
    byte[]b=new byte[n];
    int result=in.read(b);
    if(result==-1)
    {
    break;
    }
         /*for(int j=0;j<n;j++)
          {
          // System.out.flush();
           System.out.println(b[j]);
          }  */    
             
      Processor Pro = new Processor();
    byte[] a =Pro.queryUpgrade(b,address);
      i++;
      int h=a.length;
        byte[] buf=new byte[h+2];
        buf[0]=(byte)2;
        buf[1]=(byte)(h+2);int m;int w;
        for(m=0,w=2;m<h&&w<h+2;m++,w++)
        {
         buf[w]=a[m];
        }String s=new String(buf);
    out.println(s);
    out.flush();//out.close();
    //System.out.println(s); }
    try{
              Thread.sleep((int)(Math.random()*100));
          }
        catch(InterruptedException e)
           {
           }
    }
    // System.out.println(i);
    // in.close();
    } catch(IOException e){
    System.err.println("catch"+e.getMessage());
    }
    finally{
     
    try{
    out.close();
            in.close();
           socket1.close();
     }
    catch(IOException e){
    System.err.println("Socket not closed");
    //socket1.close();
    }
    }
    }public static void main(String[] args)throws IOException{ 
    ServerSocket s; 
    s=new ServerSocket(2222); 
    try{
             while(true){
                              Socket socket1=s.accept();                           try{
                              new teshi(socket1);
     
                                 /* try{
                                     Thread.sleep(10);
                                 }
                                  catch(InterruptedException e)
                                 {} */
                            }                        catch(Exception e){
                         socket1.close();
                                                 }
                             finally{
                              socket1.close();
                             }
                                                 
                           
                               try{
                                     Thread.sleep((int)(Math.random()*100));
                                 }
                                  catch(InterruptedException e)
                                 {} 
                
                                 
        }
        }finally{
    s.close();
    System.out.println(i);
    }
      
    }
    }
      

  4.   

    我连接池最大连接数设的是200,现在又出现新的问题:
    100个客户端连上来是不会出错,可以顺利查数据库,回复正确响应包,
    但1000或10000就会出现ORA-00060: deadlock detected while waiting for resource,或者是:SQLException: ORA-00001: unique constraint (HBS.XAK1ACCOUNT) violated
    晕倒!帮帮我好吗?先谢谢你们了!