mirror of
https://github.com/balkian/SWCM.git
synced 2024-11-22 12:42:29 +00:00
34 lines
779 B
Java
34 lines
779 B
Java
package ServidorConcurrente;
|
|
|
|
import java.util.*;
|
|
import java.io.*;
|
|
import java.net.*;
|
|
|
|
public class ServWebPatternConc {
|
|
public static int maxCon = 10;
|
|
public static void main (String args[]) {
|
|
try {
|
|
ServerSocket serv = new ServerSocket(8080);
|
|
System.out.println("showserver created at port 8080.");
|
|
ThreadGroup workers = new ThreadGroup("WebWorkers");
|
|
|
|
while (true) {
|
|
if(workers.activeCount()<maxCon){
|
|
System.out.println("Hay "+workers.activeCount()+" hebras corriendo.");
|
|
Socket conn = serv.accept();
|
|
Thread hs = new Thread(workers, new HebraServ(conn));
|
|
hs.start();
|
|
}
|
|
else{
|
|
try{
|
|
Thread.sleep(500);
|
|
}
|
|
catch(Exception ex){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (IOException e) { System.err.println(e); }
|
|
}
|
|
}
|