Search in sources :

Example 16 with TaskRejectedException

use of org.springframework.core.task.TaskRejectedException in project gateway-dubbox by zhuzhong.

the class ThreadPoolHandlerImpl method addTask.

@Override
public Object addTask(AbstractTask task) {
    try {
        FutureTask<OpenApiHttpSessionBean> tsFutre = new FutureTask<OpenApiHttpSessionBean>(task);
        taskExecutor.execute(tsFutre);
        while (!tsFutre.isDone()) {
        /*
                 * try { // logger.debug("waitting for result");
                 * TimeUnit.MICROSECONDS.sleep(200); } catch
                 * (InterruptedException e) { logger.error(String.format(
                 * "exception happend on executing task with ",
                 * e.getMessage())); }
                 */
        }
        return tsFutre.get();
    } catch (TaskRejectedException e) {
        logger.error("the queue reached max deepth");
        throw new OpenApiException(OpenApiServiceErrorEnum.SYSTEM_QUEUE_DEEPTH);
    } catch (Throwable e) {
        Throwable throwable = e.getCause();
        if (throwable instanceof OpenApiException) {
            throw (OpenApiException) throwable;
        }
        logger.error(String.format("exception happend on executing task with %s", e.getMessage()));
        OpenApiException ex = new OpenApiException(OpenApiServiceErrorEnum.SYSTEM_BUSY, throwable);
        throw ex;
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) FutureTask(java.util.concurrent.FutureTask) OpenApiException(com.z.gateway.common.exception.OpenApiException) OpenApiHttpSessionBean(com.z.gateway.protocol.OpenApiHttpSessionBean)

Example 17 with TaskRejectedException

use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.

the class ThreadPoolTaskExecutor method submitListenable.

@Override
public ListenableFuture<?> submitListenable(Runnable task) {
    ExecutorService executor = getThreadPoolExecutor();
    try {
        ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
        executor.execute(future);
        return future;
    } catch (RejectedExecutionException ex) {
        throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 18 with TaskRejectedException

use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.

the class TaskExecutorAdapter method submit.

@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);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) FutureTask(java.util.concurrent.FutureTask) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 19 with TaskRejectedException

use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.

the class TaskExecutorAdapter method submitListenable.

@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);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

TaskRejectedException (org.springframework.core.task.TaskRejectedException)19 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)12 ListenableFutureTask (org.springframework.util.concurrent.ListenableFutureTask)8 ExecutorService (java.util.concurrent.ExecutorService)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 FutureTask (java.util.concurrent.FutureTask)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 WorkException (javax.resource.spi.work.WorkException)2 WorkRejectedException (javax.resource.spi.work.WorkRejectedException)2 Test (org.junit.Test)2 TaskTimeoutException (org.springframework.core.task.TaskTimeoutException)2 SchedulingException (org.springframework.scheduling.SchedulingException)2 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)2 OpenApiException (com.z.gateway.common.exception.OpenApiException)1 OpenApiHttpSessionBean (com.z.gateway.protocol.OpenApiHttpSessionBean)1 Work (commonj.work.Work)1 WorkException (commonj.work.WorkException)1 WorkRejectedException (commonj.work.WorkRejectedException)1 UnknownMessageTypeException (cz.metacentrum.perun.engine.exceptions.UnknownMessageTypeException)1