/** * Grows the thread pool by one new thread if the maximum pool size * has not been reached.<p> */ private void growThreadPool() { if (m_currentThreadCount < m_maxThreadCount) { // if maximum number is not reached grow the thread pool synchronized (m_nextRunnableLock) { m_workers[m_currentThreadCount] = new CmsSchedulerThread(this, m_threadGroup, m_threadNamePrefix + m_currentThreadCount, m_threadPriority, m_makeThreadsDaemons); m_workers[m_currentThreadCount].start(); if (m_inheritLoader) { m_workers[m_currentThreadCount].setContextClassLoader(Thread.currentThread().getContextClassLoader()); } // increas the current size m_currentThreadCount++; // notify the waiting threads m_nextRunnableLock.notifyAll(); } } } }
/** * Create a scheduler thread that runs the specified runnable exactly once.<p> * * @param pool the pool to use * @param threadGroup the thread group to use * @param threadName the name for the thread * @param prio the priority of the thread * @param isDaemon controls if this should be a deamon thread or not * @param runnable the runnable to run */ CmsSchedulerThread( CmsSchedulerThreadPool pool, ThreadGroup threadGroup, String threadName, int prio, boolean isDaemon, Runnable runnable) { super(threadGroup, threadName); m_run = true; m_pool = pool; m_runnable = runnable; setPriority(prio); setDaemon(isDaemon); }
/** * Loop, executing targets as they are received.<p> */ @Override public void run() { boolean runOnce = (m_runnable != null); while (m_run) { setPriority(m_pool.getThreadPriority()); try { if (m_runnable == null) { m_runnable = m_pool.getNextRunnable(); } if (m_runnable != null) { m_runnable.run(); } } catch (InterruptedException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_INTERRUPTED_1, getName()), e); } catch (Throwable t) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_ERROR_1, getName()), t); } finally { if (runOnce) { m_run = false; } m_runnable = null; } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_THREAD_SHUTDOWN_1, getName())); } }
CmsSchedulerThread thread = new CmsSchedulerThread( this, m_threadGroup, false, runnable); thread.start();
/** * Loop, executing targets as they are received.<p> */ @Override public void run() { boolean runOnce = (m_runnable != null); while (m_run) { setPriority(m_pool.getThreadPriority()); try { if (m_runnable == null) { m_runnable = m_pool.getNextRunnable(); } if (m_runnable != null) { m_runnable.run(); } } catch (InterruptedException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_INTERRUPTED_1, getName()), e); } catch (Throwable t) { LOG.error(Messages.get().getBundle().key(Messages.LOG_THREAD_ERROR_1, getName()), t); } finally { if (runOnce) { m_run = false; } m_runnable = null; } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_THREAD_SHUTDOWN_1, getName())); } }
CmsSchedulerThread thread = new CmsSchedulerThread( this, m_threadGroup, false, runnable); thread.start();
/** * Grows the thread pool by one new thread if the maximum pool size * has not been reached.<p> */ private void growThreadPool() { if (m_currentThreadCount < m_maxThreadCount) { // if maximum number is not reached grow the thread pool synchronized (m_nextRunnableLock) { m_workers[m_currentThreadCount] = new CmsSchedulerThread( this, m_threadGroup, m_threadNamePrefix + m_currentThreadCount, m_threadPriority, m_makeThreadsDaemons); m_workers[m_currentThreadCount].start(); if (m_inheritLoader) { m_workers[m_currentThreadCount].setContextClassLoader( Thread.currentThread().getContextClassLoader()); } // increas the current size m_currentThreadCount++; // notify the waiting threads m_nextRunnableLock.notifyAll(); } } } }
/** * Create a scheduler thread that runs the specified runnable exactly once.<p> * * @param pool the pool to use * @param threadGroup the thread group to use * @param threadName the name for the thread * @param prio the priority of the thread * @param isDaemon controls if this should be a deamon thread or not * @param runnable the runnable to run */ CmsSchedulerThread( CmsSchedulerThreadPool pool, ThreadGroup threadGroup, String threadName, int prio, boolean isDaemon, Runnable runnable) { super(threadGroup, threadName); m_run = true; m_pool = pool; m_runnable = runnable; setPriority(prio); setDaemon(isDaemon); }