Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>TaskExecutor</code> interface is a fire-and-forget interface, for use when you don't care when the task finishes. It's the simplest async abstraction that Spring offers.</p> <p>There is , however, an enhanced interface, <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/core/task/AsyncTaskExecutor.html#submit(java.lang.Runnable)" rel="noreferrer"><code>AsyncTaskExecutor</code></a>, which provides additional methods, including <code>submit()</code> methods that return a <code>Future</code>, which let you wait on the result.</p> <p>Spring provides the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html" rel="noreferrer"><code>ThreadPoolTaskExecutor</code></a> class, which implement both <code>TaskExecutor</code> and <code>AsyncTaskExecutor</code>.</p> <p>In your specific case, I would re-implement the <code>Runnable</code> as a <code>Callable</code>, and return the <code>commandResults</code> from the <code>Callable.call()</code> method. The <code>getCommandResults</code> method can then be reimplemented as:</p> <pre><code>public List&lt;String&gt; getCommandResults(String command) { Future&lt;List&lt;String&gt;&gt; futureResults = taskExecutor.submit(new CommandTask(command)); return futureResults.get(); } </code></pre> <p>This method will submit the task asynchronously, and then wait for it to complete before returning the results returned from the <code>Callable.call()</code> method. This also lets you get rid of the <code>commandResults</code> field.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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