java - why the separate threads are not created? -
i new socket programming , trying write simple cmd line chat application. use code below accept connection , create new thread same,but no new thread created ,and no more 1 clients supported(which usual when threads not used),
public class chatserver extends thread{ public static socket client; public static void main(string a[]) throws exception{ serversocket srv = new serversocket(4444); if((client = srv.accept())!=null){ new newthread(client); } } } class newthread extends thread{ private socket client; public newthread(socket client){ super("chatchild"); this.client = client; start(); }
why threads not created?i reffered examples @ "oracle.com" 1 of contains code same not able figure out exact sequence happen , when???the snippet exaple code accepts connection , creates thread::
while (listening) new kkmultiserverthread(serversocket.accept()).start();
now here listening bool var sat true never set false anywhere in code.???how work?
you have continually call accept() create other threads:
public static void main(string a[]) throws exception{ serversocket srv = new serversocket(4444); while (listening) { new newthread(srv.accept()); } }
the listening variable should set false if , when want stop server.
Comments
Post a Comment