multithreading - Java thread not stopping even when while loop is done -
i have client <-> server application. problem when click button "exit" not kill entire thread. kills process, thread still remains active. if click "x" button joptionpane.showconfirmdialog stopping everything, button same (to terminated).
p.p. "exit" button starts jswingworker calling disconnect()
@override public void run() { synchronized (this) { while (!serverdownaftertry && !serverclosedbybutton) { multicastsocket = connecttomulticastaddress(multicastip); mediator = new mediator(multicastsocket, this, objectoutput, username); mediator.setsocketip(clientsocket.getinetaddress().tostring()); mediator.setsocketport(clientsocket.getport()); string input = ""; if (connected) { mediator.writeonmulticastaddress("user_connected " + this.username); mediator.executecommands("system_message " + this.username, clientgui); input = mediator.listentomulticast(multicastsocket); } while (!multicastsocket.isclosed()) { input = mediator.listentomulticast(multicastsocket); if (input != null) { mediator.executecommands(input, clientgui); } } } } } public void disconnect() { clientgui.dispose(); serverclosedbybutton = true; multicastsocket.close(); try { objectoutput.close(); clientsocket.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
} happens when click exit button: enter image description here
this happens when click "x" button on jframe(terminated): enter image description here
when use swing, need terminate vm exit. example using of system.exit(0);
Comments
Post a Comment