java - Second thread is not reached -


i trying start 2 threads, 1 tcp , 1 udp

package com.main;  import com.utility.hibernateutil;  public class serverstarter {      public static void main(string[] args) {         system.out.print("reach 1");         thread tcp = new thread(new tcpserverstarter());         tcp.start();         system.out.print("reach 2");         thread udp = new thread(new udpserverstarter());         system.out.print("reach 3");         hibernateutil.buildsessionfactory();         system.out.print("reach 4");     }      public static class tcpserverstarter extends thread{          public tcpserverstarter(){             new tcpserver(8500).run();         }     }      public static class udpserverstarter extends thread{          public udpserverstarter(){             new udpserver(1000).run();         }     } } 

only "reach 1" printed. read may occur if have single core, have 2 cores.

put code method called run() instead of calling constructor (calling run() block execution)

public static class tcpserverstarter extends thread {      @override     public void run() {         new tcpserver(8500).run();     } }  public static class udpserverstarter extends thread {      @override     public void run() {         new udpserver(1000).run();     } } 

}

if udpserver , tcpserver extends thread or implements runnable, can start them directly start() method w/o creating wrapper classes.


Comments