I did a little client server application in Java on LinuxOS, where the server receives different commands from the client and processes them by starting different threads. There is one specific thread for each command.
My main-program starts a thread, that responds to different commands and consists simplified of one infinite loop. There is no exit out of the loop yet. This Thread prints to the Terminal, where the main-program was started, but the commands after “.start()” aren’t executed.
ServerSend servSend = new ServerSend(arg);
System.out.println("1");
servSend.start();
System.out.println("2");`
So “2” is never printed, whereas some “System.out.println()” inside the thread work. Does anybody have an idea why?
If you are trying to spawn a new thread, I assume
ServerSendimplementsjava.lang.Runnableor extendsjava.lang.Threadin which case you should be overwriting thepublic void run()method, not thestart()method.ie:
And then use it with;
Public access to
threadallows you to do things like;This is my preferred method (using
Runnable) others prefer to extendThread. This answer pretty much sums up my thinking: https://stackoverflow.com/a/541506/980520