当前位置: 代码迷 >> Java Web开发 >> list集合的有关问题
  详细解决方案

list集合的有关问题

热度:85   发布时间:2016-04-16 21:59:46.0
list集合的问题
package com.vo;
import java.io.IOException;  
import java.net.ServerSocket;  
import java.net.Socket;  
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
  
  
/** 
 * socket 线程类 
 * @author zhangzhongwen 
 * 
 */  
public class SocketThread extends Thread{  
    private ServerSocket serverSocket = null;
    
    private static List<Thread> threads=new ArrayList<Thread>();

public static List<Thread> getThreads() {
return threads;
}

public SocketThread(ServerSocket serverScoket){  
        try {  
            if(null == serverSocket){  
                this.serverSocket = new ServerSocket(12345);  
                System.out.println("socket start");  
            }  
        } catch (Exception e) {   
            System.out.println("SocketThread创建socket服务出错");  
            e.printStackTrace();  
        }  
  
    }  
      
    public void run(){  
        while(!this.isInterrupted()){  
            try { 
                Socket socket = serverSocket.accept();  
                  System.out.println(socket.toString());
                if(null != socket && !socket.isClosed()){  
                
                    //处理接受的数据  
                   Thread t= new SocketOperate(socket); 
                   System.out.println("collections.set");
//                   System.out.println(collections);
                   threads.add(t);
                   t.start();
                }  
                System.out.println(threads);
                socket.setSoTimeout(30000);  
                  
            }catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
    }  
      
      
    public void closeSocketServer(){  
       try {  
            if(null!=serverSocket && !serverSocket.isClosed())  
            {  
             serverSocket.close();  
            }  
       } catch (IOException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
       }  
     }  
      
  相关解决方案