2 thoughts on “Learn How to create a multi-threaded Server in Java

  1. Hello sir
    This is very nice and useful post about multi-threading .

    Thank You for this post
    Keep posting for us.

  2. This code contains multiple errors
    in the opnSvrSocket() method

    this.serverSocketVal = new serverSocketVal(this.serverPortVal);

    should be changed to
    this.serverSocketVal = new ServerSocket(this.serverPortVal);

    and
    Listing 3: Client code to start multiple threads

    Public class Client{
    publics static void main(String [] agrs) throws IOException{
    ServerMultithreaded newServer = new ServerMultithreaded(9191);
    new Thread(newServer).start();

    try {
    Thread.sleep(15 * 1000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    System.out.println(“Stopping newServer”);
    newServer.stop();
    }
    }

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14
    Public class Client{
    publics static void main(String [] agrs) throws IOException{

    furthermore the ‘client code to start multiple threads’ is server start code.
    to initiate clients tell your pupils to use a browser with an adress http://localhost:9191

    should be
    public class Client{
    public static void main(String [] agrs) throws IOException{

Leave a Reply

Your email address will not be published. Required fields are marked *