Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 16 17 package org.springframework.scheduling.backportconcurrent; 18 19 import edu.emory.mathcs.backport.java.util.concurrent.Executor; 20 import edu.emory.mathcs.backport.java.util.concurrent.Executors; 21 import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException; 22 23 import org.springframework.core.task.TaskRejectedException; 24 import org.springframework.scheduling.SchedulingTaskExecutor; 25 26 53 public class ConcurrentTaskExecutor implements SchedulingTaskExecutor, Executor { 54 55 private Executor concurrentExecutor; 56 57 58 63 public ConcurrentTaskExecutor() { 64 setConcurrentExecutor(null); 65 } 66 67 72 public ConcurrentTaskExecutor(Executor concurrentExecutor) { 73 setConcurrentExecutor(concurrentExecutor); 74 } 75 76 79 public void setConcurrentExecutor(Executor concurrentExecutor) { 80 this.concurrentExecutor = 81 (concurrentExecutor != null ? concurrentExecutor : Executors.newSingleThreadExecutor()); 82 } 83 84 88 public Executor getConcurrentExecutor() { 89 return this.concurrentExecutor; 90 } 91 92 93 97 public void execute(Runnable task) { 98 try { 99 this.concurrentExecutor.execute(task); 100 } 101 catch (RejectedExecutionException ex) { 102 throw new TaskRejectedException( 103 "Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex); 104 } 105 } 106 107 110 public boolean prefersShortLivedTasks() { 111 return true; 112 } 113 114 } 115
| Popular Tags
|