Note that there are some explanatory texts on larger screens.

plurals
  1. POI need clarification on the ThreadpoolExecutor beforeExecute and afterExecute hooks
    text
    copied!<p>I am using threadpools in my application. I have subclassed the TreadPoolExecutor and overriden the methods beforeExecute, afterExecute and terminated for statistical purposes.<br> I also have implemented my own ThreadFactory and overriden the newThread method. </p> <p>I understand that the threadpool wrapper class creates a dozen of "callable" tasks and calls the invokeAll method to get the results. In each task there is an interface object. The base X object implements the interface and has been subclassed a number of times. So when the threadpool is executed it launches childs of the object X. </p> <p>From a code perspective it looks a bit like:</p> <pre><code>the wrapper threapool class: List&lt;DoTask&gt; tasks; tasks.add(new DoTask(new A("A")); tasks.add(new DoTask(new B("B")); tasks.add(new DoTask(new C("C")); results = threadpool.invokeAll(tasks, 60, TimeUnit.Seconds); </code></pre> <hr> <pre><code>in my DoTask class: public DoTask implements Callable constructor: DoTask(ifaceX x) </code></pre> <hr> <pre><code>im my Base class X: public class X implements ifaceX In my child class A, B, C: public A extends X </code></pre> <p>My questions is, how to retrieve information kept in the callable task when I call the before and after execute hooks? or I guess what I am trying to do is give a specific name to each thread of the threadpool is that possible? </p> <p>I can clearly see the information is there in the Eclipse variables view in debug mode hidden in the Runnable object/FutureTask/callable. </p> <p>I do not understand why I only have to override methods (beforeExecute, afterExecute) with Runnable objects and no Callable ones (since I need to retrieve results). Something I am missing or do not understand? Maybe I need to subclass FutureTask not sure?</p> <p>Thanks for your help,</p>
 

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