Package java.util.concurrent

Examples of java.util.concurrent.RejectedExecutionException


                new PoolExecutorThreadFactory(threadGroup, name + ".internal-", classLoader),
                new RejectedExecutionHandler() {
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        String message = "Internal executor rejected task: " + r + ", because client is shutting down...";
                        logger.finest(message);
                        throw new RejectedExecutionException(message);
                    }
                });
        executor = new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(),
                new PoolExecutorThreadFactory(threadGroup, name + ".cached-", classLoader),
                new RejectedExecutionHandler() {
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        String message = "Internal executor rejected task: " + r + ", because client is shutting down...";
                        logger.finest(message);
                        throw new RejectedExecutionException(message);
                    }
                });


        scheduledExecutor = Executors.newSingleThreadScheduledExecutor(
View Full Code Here


         } else {
            throw new IllegalArgumentException("Runnable command is not Serializable  " + command);
         }
         cmd.execute();
      } else {
         throw new RejectedExecutionException();
      }
   }
View Full Code Here

            execute(work);
        } catch (RejectedExecutionException ree) {
            try {
                getQueue().offer(work, timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException ie) {
                throw new RejectedExecutionException(ie);
            }
        }   
    }
View Full Code Here

        return taskQ.remainingCapacity();
    }

    public void execute(Runnable command) {
        if (!taskQ.offer(command)) {
            throw new RejectedExecutionException("Executor[" + name + "] is overloaded!");
        }
        addNewWorkerIfRequired();
    }
View Full Code Here

        try {
            lock.lockInterruptibly();
            try {
                for (;;) {
                    if (stop) {
                        throw new RejectedExecutionException("Executor is stopped");
                    }
                    // Try core thread first, then queue, then extra thread
                    final int count = threadCount;
                    if (count < corePoolSize) {
                        startNewThread(task);
                        threadCount = count + 1;
                        return;
                    }
                    // next queue...
                    final Queue<Runnable> queue = this.queue;
                    if (queue.offer(task)) {
                        enqueueCondition.signal();
                        return;
                    }
                    // extra threads?
                    if (count < maxPoolSize) {
                        startNewThread(task);
                        threadCount = count + 1;
                        return;
                    }
                    rejectCount++;
                    // how to reject the task...
                    switch (rejectionPolicy) {
                        case ABORT:
                            throw new RejectedExecutionException("Executor is busy");
                        case BLOCK:
                            removeCondition.await();
                            break;
                        case DISCARD:
                            return;
                        case DISCARD_OLDEST:
                            if (queue.poll() != null) {
                                queue.add(task);
                                enqueueCondition.signal();
                            }
                            return;
                        case HANDOFF:
                            handoffExecutor.execute(task);
                            return;
                    }
                }
            } finally {
                lock.unlock();
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RejectedExecutionException("Thread interrupted");
        }
    }
View Full Code Here

     */
    public void execute(final Runnable command) throws RejectedExecutionException {
        final Executor[] executors = this.executors;
        final int len = executors.length;
        if (len == 0) {
            throw new RejectedExecutionException("No executors available to run task");
        }
        executors[seq.getAndIncrement() % len].execute(command);
    }
View Full Code Here

            lock.lockInterruptibly();
            try {
                while (! queue.offer(command)) {
                    switch (policy) {
                        case ABORT:
                            throw new RejectedExecutionException();
                        case BLOCK:
                            removeCondition.await();
                            break;
                        case DISCARD:
                            return;
                        case DISCARD_OLDEST:
                            if (queue.poll() != null) {
                                queue.add(command);
                            }
                            break;
                        case HANDOFF:
                            handoffExecutor.execute(command);
                            return;
                    }
                }
                if (! running) {
                    running = true;
                    boolean ok = false;
                    try {
                        parent.execute(runner);
                        ok = true;
                    } finally {
                        if (! ok) {
                            running = false;
                        }
                    }
                }
            } finally {
                lock.unlock();
            }
        } catch (InterruptedException e) {
            throw new RejectedExecutionException();
        }
    }
View Full Code Here

        shutdown.set(false);
        if (executor != null) {
            executor.setRejectedExecutionHandler(new RejectedExecutionHandler() {
                public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
                    ProcessCall call = (ProcessCall)runnable;
                    call.exchange.setException(new RejectedExecutionException());
                    call.callback.done(false);
                }
            });
        }
        ServiceHelper.startServices(processors);
View Full Code Here

            this.processor = processor;
        }

        public void run() {
            if (shutdown.get()) {
                exchange.setException(new RejectedExecutionException());
                callback.done(false);
            } else {
                try {
                    processor.process(exchange);
                } catch (Exception ex) {
View Full Code Here

            executor.execute(call);
            return false;
        } catch (RejectedExecutionException e) {
            if (callerRunsWhenRejected) {
                if (shutdown.get()) {
                    exchange.setException(new RejectedExecutionException());
                } else {
                    callback.done(true);
                }
            } else {
                exchange.setException(e);
View Full Code Here

TOP

Related Classes of java.util.concurrent.RejectedExecutionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.