Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just setting the <code>Thread</code>s created by the <code>ExecutorService</code> to daemon won't help (though you do need to do this). You can set your <code>ExecutorService</code> <code>Thread</code>s to daemon like so:</p> <pre><code>executor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); </code></pre> <p>The real problem you are having is with this code block:</p> <pre><code> for (Future&lt;String&gt; f : result) { try { parsedValue = f.get(); System.out.println("Return Value - " + parsedValue); } catch (CancellationException e) { System.out.println("Cancelled"); parsedValue = ""; f.cancel(true); } } executor.shutdownNow(); </code></pre> <p>More specifically, this code will hang forever here:</p> <pre><code>parsedValue = f.get(); </code></pre> <p>The reason for this is simple, the <code>Future#get</code> method "Waits if necessary for the computation to complete, and then retrieves its result.", but the computation will never complete because it is in an infinite loop. Not even an interrupt from <code>ThreadPoolExecutor#shutdownNow</code> or <code>Future#cancel(true)</code> will help you because your <code>Callable</code> code is not perofrming a blocking operation or otherwise checking for an interrupt.</p> <p>From here, you have two options:</p> <ol> <li>Use the form of <code>Future#get</code> that takes a <code>long timeout</code> argument.</li> <li>Use <code>Future#isDone</code> to determine if the <code>Future#get</code> method has a value to return prior to actually calling <code>Future#get</code>.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload