歡迎您光臨本站 註冊首頁

求解tomcat線程池源碼

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

求解tomcat線程池源碼

最近讀tomcat源代碼,其中線程池部分有一段完全看不懂,ThreadPoolExecutor.java源文件中的一個方法,不知道這個這個方法起什麼作用,以及Context reload是什麼意思,在什麼情況下需要進行Context reload public void contextStopping() {
        this.lastContextStoppedTime.set(System.currentTimeMillis());

        // save the current pool parameters to restore them later
        int savedCorePoolSize = this.getCorePoolSize();
        TaskQueue taskQueue =
                getQueue() instanceof TaskQueue ? (TaskQueue) getQueue() : null;
        if (taskQueue != null) {
            // note by slaurent : quite oddly threadPoolExecutor.setCorePoolSize
            // checks that queue.remainingCapacity()==0. I did not understand
            // why, but to get the intended effect of waking up idle threads, I
            // temporarily fake this condition.
            taskQueue.setForcedRemainingCapacity(Integer.valueOf(0));
        }

        // setCorePoolSize(0) wakes idle threads
        this.setCorePoolSize(0);

        // wait a little so that idle threads wake and poll the queue again,
        // this time always with a timeout (queue.poll() instead of
        // queue.take())
        // even if we did not wait enough, TaskQueue.take() takes care of timing
        // out, so that we are sure that all threads of the pool are renewed in
        // a limited time, something like
        // (threadKeepAlive + longest request time)
        try {
            Thread.sleep(200L);
        } catch (InterruptedException e) {
            // yes, ignore
        }

        if (taskQueue != null) {
            // ok, restore the state of the queue and pool
            taskQueue.setForcedRemainingCapacity(null);
        }
        this.setCorePoolSize(savedCorePoolSize);
    }
《解決方案》

我自己頂一下:-L

[火星人 ] 求解tomcat線程池源碼已經有166次圍觀

http://coctec.com/docs/service/show-post-11286.html