I am using OrderedThreadPoolExecutor to handle expensive logical works.But
found can't receive event on IoHandler. I worked through MINA source code ,
and found the issue .
Look at the red code, when there is exception throws at runTasks(...), but
we don't catch it, it will break the for loop, finally MINA removed the
worker(the red code in finally block) without idleWorkers decreased(see
blue code), that's mean idleWorkers > 0.
As a result after MINA runing a certain time,there is no worker running,but
can't add new worker to the thread pool, because we have a check idleWorkers
 == 0  on addWorkerIfNecessary().

                public void run() {
            thread = Thread.currentThread();

            try {
                for (;;) {
                    IoSession session = fetchSession();

                    idleWorkers.decrementAndGet();

                    if (session == null) {
                        synchronized (workers) {
                            if (workers.size() > getCorePoolSize()) {
                                // Remove now to prevent duplicate exit.
                                workers.remove(this);
                                break;
                            }
                        }
                    }

                    if (session == EXIT_SIGNAL) {
                        break;
                    }

                    try {
                        if (session != null) {
                            runTasks(getSessionTasksQueue(session));
                        }
                    } finally {
                        idleWorkers.incrementAndGet();
                    }
                }
            } finally {
                synchronized (workers) {
                    workers.remove(this);
                    OrderedThreadPoolExecutor.this.completedTaskCount +=
                  completedTaskCount.get();
                    workers.notifyAll();
                }
            }
        }

Reply via email to