Earlier I wrote a query about Java threads. ( link text )
And based on the answers I decided to implement them. So, I made this coding bit on a machine with 2 processor cores. The code is as follows
import java.net.*;
import java.io.*;
public class thready implements Runnable{
private Socket num;
public thready(Socket a) {
this.num=a;
}
public void run() {
try {
BufferedInputStream is = new BufferedInputStream(num.getInputStream());
System.out.println("Connected to port"+num);
} catch (IOException ex) {
}
}
public static void main(String [] args)
{
int port = 80;
int port1= 81;
try{
ServerSocket socket1 = new ServerSocket(port);
ServerSocket socket2 = new ServerSocket(port1);
while (true) {
Socket connection = socket1.accept();
Socket connection1 = socket2.accept();
Runnable runnable =new thready(connection);
Runnable run= new thready(connection1);
Thread t1=new Thread(runnable);
Thread t2=new Thread(run);
t1.start();
t2.start();
}
}
catch(Exception e)
{
} }}
Hyperterminal 890, 81 ( 2 ), , , , " " " , (80 81). , , , , , , , . , , .
.