<div dir="ltr">"<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">  public abstract void setPriority(int priority);" ? Changing priority on an already submitted task seems strange.<br><br>
I agree with David, just use a PriorityBlockingQueue [</span><font face="arial, sans-serif"><a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/PriorityBlockingQueue.html">http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/PriorityBlockingQueue.html</a>] for the submission queue of the TPE and provide a Comparator that checks for your PriorityCallable and puts non-PriorityCallable-Callables at an appropriate default priority.</font></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 27, 2014 at 6:16 AM, David Holmes <span dir="ltr"><<a href="mailto:davidcholmes@aapt.net.au" target="_blank">davidcholmes@aapt.net.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can't you just use your PriorityCallable with a custom PriorityQueue and<br>
standard ThreadPoolExecutor?<br>
<span class="HOEnZb"><font color="#888888"><br>
David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> -----Original Message-----<br>
> From: <a href="mailto:concurrency-interest-bounces@cs.oswego.edu">concurrency-interest-bounces@cs.oswego.edu</a><br>
> [mailto:<a href="mailto:concurrency-interest-bounces@cs.oswego.edu">concurrency-interest-bounces@cs.oswego.edu</a>]On Behalf Of DT<br>
> Sent: Friday, 27 June 2014 2:08 PM<br>
> To: <a href="mailto:concurrency-interest@cs.oswego.edu">concurrency-interest@cs.oswego.edu</a><br>
> Subject: [concurrency-interest] Custom ThreadPoolExecutor implementation<br>
> to handle priority based Callable tasks<br>
><br>
><br>
> If we were to control Callable Tasks with Priorities and to manage<br>
> execution of those callable tasks through ThreadPoolExecutor we would<br>
> have to implement custom ThreadPoolExecutor and PriorityCallable (see a<br>
> suggestion below). What other ways to accomplish this do you see ?<br>
><br>
> public interface PriorityCallable extends Callable<Object> {<br>
>      public abstract void setPriority(int priority);<br>
>      ...<br>
> }<br>
><br>
> public class CustomThreadPoolExecutor  extends ThreadPoolExecutor {<br>
> ...<br>
> ...<br>
> public <T> List<Future<T>> customInvokeAll(<br>
>                  Collection<? extends Callable<T>> tasks, long timeout,<br>
> TimeUnit unit) // pass PriorityCallable<br>
>                  throws InterruptedException {<br>
>              if (tasks == null || unit == null)<br>
>                  throw new NullPointerException();<br>
>              long nanos = unit.toNanos(timeout);<br>
>              List<Future<T>> futures = new<br>
> ArrayList<Future<T>>(tasks.size());<br>
>              boolean done = false;<br>
>              try {<br>
>                  // handle Priority based Callable tasks here, though<br>
> can expect timing issues<br>
>                  // custom logic to group Callable tasks , if (priority<br>
> == 1, 2, 3 create group of callables, etc )<br>
>                  for (Callable<T> t : tasks)<br>
>                      futures.add(newTaskFor(t));<br>
><br>
>                  long lastTime = System.nanoTime();<br>
><br>
>                  // Interleave time checks and calls to execute in case<br>
>                  // executor doesn't have any/much parallelism.<br>
>                  Iterator<Future<T>> it = futures.iterator();<br>
>                  while (it.hasNext()) {<br>
>                      execute((Runnable)(it.next())); // should we expect<br>
> futures get executed within the same timeframe for Callables with<br>
> different priorities<br>
>                      long now = System.nanoTime();<br>
>                      nanos -= now - lastTime;<br>
>                      lastTime = now;<br>
>                      if (nanos <= 0)<br>
>                          return futures;<br>
>                  }<br>
><br>
>                  for (Future<T> f : futures) {<br>
>                      if (!f.isDone()) {<br>
>                          if (nanos <= 0)<br>
>                              return futures;<br>
>                          try {<br>
>                              f.get(nanos, TimeUnit.NANOSECONDS);<br>
>                          } catch (CancellationException ignore) {<br>
>                          } catch (ExecutionException ignore) { // Should<br>
> we cancel tasks based on the priority as well?<br>
>                          } catch (TimeoutException toe) {<br>
>                              return futures;<br>
>                          }<br>
>                          long now = System.nanoTime();<br>
>                          nanos -= now - lastTime;<br>
>                          lastTime = now;<br>
>                      }<br>
>                  }<br>
>                  done = true;<br>
>                  return futures;<br>
>              } finally {<br>
>                  if (!done)<br>
>                      for (Future<T> f : futures)<br>
>                          f.cancel(true);<br>
>              }<br>
>          }<br>
> ...<br>
> }<br>
><br>
> Thank you,<br>
> dt<br>
> <a href="http://www.flyingtroika.com/" target="_blank">http://www.flyingtroika.com/</a><br>
><br>
> _______________________________________________<br>
> Concurrency-interest mailing list<br>
> <a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a><br>
> <a href="http://cs.oswego.edu/mailman/listinfo/concurrency-interest" target="_blank">http://cs.oswego.edu/mailman/listinfo/concurrency-interest</a><br>
<br>
_______________________________________________<br>
Concurrency-interest mailing list<br>
<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a><br>
<a href="http://cs.oswego.edu/mailman/listinfo/concurrency-interest" target="_blank">http://cs.oswego.edu/mailman/listinfo/concurrency-interest</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Times;font-variant:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px">
Cheers,</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px">√</div></span></div></div>
</div>