Question

So, I'm searching on net for a while and now I'm confused... do I need to explicitly end thread after code is executed or thread does it automatically?
Code:

Runnable waitForInput = new Runnable() {
    public void run() {
        while (!inputOK) {
            try {
               Thread.sleep(100);
            } catch (Exception e) {}
        }
        if (!ret_val.equals("")) {
            port = ret_val;
        }
        inputOK = false;
        ret_val = "";
    }
};      
Thread inputW = new Thread(waitForInput);
inputW.start();
Was it helpful?

Solution

The Thread ends when the method run ends. Since you have while loop you have to force explicitly the exit condition

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top