谢谢
1 个解决方案
#1
ServerSocket ss = new ServerSocket(10000,10);
while(true){
Thread th = new mySocket(ss.accept());
th.start();
}
class mySocket extends Thread{
protected Socket sock;
public mySocket(Socket sock){ this.sock = sock }
public void run(){ //run you application }
}
主进程只需要监视是否有传入连接,有accept()的时候,新建一个线程来处理就不会占用主线程资源了
while(true){
Thread th = new mySocket(ss.accept());
th.start();
}
class mySocket extends Thread{
protected Socket sock;
public mySocket(Socket sock){ this.sock = sock }
public void run(){ //run you application }
}
主进程只需要监视是否有传入连接,有accept()的时候,新建一个线程来处理就不会占用主线程资源了
#1
ServerSocket ss = new ServerSocket(10000,10);
while(true){
Thread th = new mySocket(ss.accept());
th.start();
}
class mySocket extends Thread{
protected Socket sock;
public mySocket(Socket sock){ this.sock = sock }
public void run(){ //run you application }
}
主进程只需要监视是否有传入连接,有accept()的时候,新建一个线程来处理就不会占用主线程资源了
while(true){
Thread th = new mySocket(ss.accept());
th.start();
}
class mySocket extends Thread{
protected Socket sock;
public mySocket(Socket sock){ this.sock = sock }
public void run(){ //run you application }
}
主进程只需要监视是否有传入连接,有accept()的时候,新建一个线程来处理就不会占用主线程资源了