org.springframework.core.task.TaskRejectedException Java Examples

The following examples show how to use org.springframework.core.task.TaskRejectedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConcurrentTaskScheduler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
	try {
		if (this.enterpriseConcurrentScheduler) {
			return new EnterpriseConcurrentTriggerScheduler().schedule(decorateTask(task, true), trigger);
		}
		else {
			ErrorHandler errorHandler =
					(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
			return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #2
Source File: ChannelHandlerCallBack.java    From WeCross with Apache License 2.0 6 votes vote down vote up
public void onMessage(ChannelHandlerContext ctx, ByteBuf message) {
    /*
     use thread pool first onMessage may block
    */
    Node node = (Node) (ctx.channel().attr(AttributeKey.valueOf("node")).get());

    if (threadPool == null) {
        callBack.onMessage(ctx, node, message);
    } else {
        try {
            threadPool.execute(
                    new Runnable() {
                        @Override
                        public void run() {
                            callBack.onMessage(ctx, node, message);
                        }
                    });
        } catch (TaskRejectedException e) {
            logger.warn(" TaskRejectedException : {}, message: {}", e, message);
        }
    }
}
 
Example #3
Source File: ResourceBlockHeaderManager.java    From WeCross with Apache License 2.0 6 votes vote down vote up
private void runBlockHeaderCallbackTasks() {
    Queue<Runnable> tasks = getBlockHeaderCallbackTasks();

    ConcurrentLinkedQueue<Runnable> concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
    setBlockHeaderCallbackTasks(concurrentLinkedQueue);

    boolean writeBack = false;
    for (Runnable task : tasks) {
        if (writeBack) {
            concurrentLinkedQueue.add(task);
            if (logger.isDebugEnabled()) {
                logger.debug(" write task back to queue, task: {}", task);
            }
        } else {
            try {
                threadPool.execute(task);
            } catch (TaskRejectedException e) {
                logger.warn(" TaskRejectedException: {}", e);
                concurrentLinkedQueue.add(task);
                writeBack = true;
            }
        }
    }
}
 
Example #4
Source File: TaskExecutorAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public <T> Future<T> submit(Callable<T> task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<T> future = new FutureTask<>(task);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #5
Source File: ConcurrentTaskScheduler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
	try {
		if (this.enterpriseConcurrentScheduler) {
			return new EnterpriseConcurrentTriggerScheduler().schedule(decorateTask(task, true), trigger);
		}
		else {
			ErrorHandler errorHandler =
					(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
			return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #6
Source File: TaskExecutorAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Future<?> submit(Runnable task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<Object> future = new FutureTask<>(task, null);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #7
Source File: TaskExecutorAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public <T> Future<T> submit(Callable<T> task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<T> future = new FutureTask<>(task);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #8
Source File: TaskExecutorAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Future<?> submit(Runnable task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<Object> future = new FutureTask<>(task, null);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #9
Source File: TaskExecutorAdapter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> Future<T> submit(Callable<T> task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<T> future = new FutureTask<T>(task);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #10
Source File: TaskExecutorAdapter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Future<?> submit(Runnable task) {
	try {
		if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
			return ((ExecutorService) this.concurrentExecutor).submit(task);
		}
		else {
			FutureTask<Object> future = new FutureTask<Object>(task, null);
			doExecute(this.concurrentExecutor, this.taskDecorator, future);
			return future;
		}
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #11
Source File: ThreadPoolTaskExecutor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Future<?> submit(Runnable task) {
	ExecutorService executor = getThreadPoolExecutor();
	try {
		return executor.submit(task);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #12
Source File: TaskExecutorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
	try {
		ListenableFutureTask<T> future = new ListenableFutureTask<>(task);
		doExecute(this.concurrentExecutor, this.taskDecorator, future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #13
Source File: ThreadPoolTaskExecutor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute(Runnable task) {
	Executor executor = getThreadPoolExecutor();
	try {
		executor.execute(task);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #14
Source File: ThreadPoolTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Future<T> submit(Callable<T> task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		Callable<T> taskToUse = task;
		if (this.errorHandler != null) {
			taskToUse = new DelegatingErrorHandlingCallable<T>(task, this.errorHandler);
		}
		return executor.submit(taskToUse);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #15
Source File: ThreadPoolTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		executor.execute(errorHandlingTask(future, false));
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #16
Source File: ThreadPoolTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
	ScheduledExecutorService executor = getScheduledExecutor();
	try {
		ErrorHandler errorHandler =
				(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
		return new ReschedulingRunnable(task, trigger, executor, errorHandler).schedule();
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #17
Source File: ThreadPoolTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		ListenableFutureTask<T> future = new ListenableFutureTask<T>(task);
		executor.execute(errorHandlingTask(future, false));
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #18
Source File: ThreadPoolTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
	ScheduledExecutorService executor = getScheduledExecutor();
	long initialDelay = startTime.getTime() - System.currentTimeMillis();
	try {
		return executor.schedule(errorHandlingTask(task, false), initialDelay, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #19
Source File: TaskExecutorAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
	try {
		ListenableFutureTask<T> future = new ListenableFutureTask<T>(task);
		doExecute(this.concurrentExecutor, this.taskDecorator, future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #20
Source File: TaskExecutorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
		doExecute(this.concurrentExecutor, this.taskDecorator, future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #21
Source File: TaskExecutorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Delegates to the specified JDK concurrent executor.
 * @see java.util.concurrent.Executor#execute(Runnable)
 */
@Override
public void execute(Runnable task) {
	try {
		doExecute(this.concurrentExecutor, this.taskDecorator, task);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
Example #22
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay) {
	ScheduledExecutorService executor = getScheduledExecutor();
	try {
		return executor.scheduleWithFixedDelay(errorHandlingTask(task, true), 0, delay, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #23
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
	ScheduledExecutorService executor = getScheduledExecutor();
	long initialDelay = startTime.getTime() - System.currentTimeMillis();
	try {
		return executor.scheduleWithFixedDelay(errorHandlingTask(task, true), initialDelay, delay, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #24
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
	ScheduledExecutorService executor = getScheduledExecutor();
	try {
		return executor.scheduleAtFixedRate(errorHandlingTask(task, true), 0, period, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #25
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
	ScheduledExecutorService executor = getScheduledExecutor();
	long initialDelay = startTime.getTime() - System.currentTimeMillis();
	try {
		return executor.scheduleAtFixedRate(errorHandlingTask(task, true), initialDelay, period, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #26
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
	ScheduledExecutorService executor = getScheduledExecutor();
	long initialDelay = startTime.getTime() - System.currentTimeMillis();
	try {
		return executor.schedule(errorHandlingTask(task, false), initialDelay, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #27
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
	ScheduledExecutorService executor = getScheduledExecutor();
	try {
		ErrorHandler errorHandler = this.errorHandler;
		if (errorHandler == null) {
			errorHandler = TaskUtils.getDefaultErrorHandler(true);
		}
		return new ReschedulingRunnable(task, trigger, executor, errorHandler).schedule();
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #28
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		ListenableFutureTask<T> listenableFuture = new ListenableFutureTask<>(task);
		executeAndTrack(executor, listenableFuture);
		return listenableFuture;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #29
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		ListenableFutureTask<Object> listenableFuture = new ListenableFutureTask<>(task, null);
		executeAndTrack(executor, listenableFuture);
		return listenableFuture;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
Example #30
Source File: ThreadPoolTaskScheduler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> Future<T> submit(Callable<T> task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		Callable<T> taskToUse = task;
		ErrorHandler errorHandler = this.errorHandler;
		if (errorHandler != null) {
			taskToUse = new DelegatingErrorHandlingCallable<>(task, errorHandler);
		}
		return executor.submit(taskToUse);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}