1 10 11 package org.mule.util.concurrent; 12 13 import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException; 14 import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionHandler; 15 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; 16 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; 17 18 23 public class WaitPolicy implements RejectedExecutionHandler 25 { 26 private final long _time; 27 private final TimeUnit _timeUnit; 28 29 32 public WaitPolicy() 33 { 34 this(Long.MAX_VALUE, TimeUnit.SECONDS); 36 } 37 38 42 public WaitPolicy(long time, TimeUnit timeUnit) 43 { 44 super(); 45 _time = (time < 0 ? Long.MAX_VALUE : time); 46 _timeUnit = timeUnit; 47 } 48 49 public void rejectedExecution(Runnable r, ThreadPoolExecutor e) 50 { 51 try 52 { 53 if (e.isShutdown() || !e.getQueue().offer(r, _time, _timeUnit)) 54 { 55 throw new RejectedExecutionException(); 56 } 57 } 58 catch (InterruptedException ie) 59 { 60 Thread.currentThread().interrupt(); 61 throw new RejectedExecutionException(ie); 62 } 63 } 64 65 } 66 | Popular Tags |