/*********************************************************************
* Jdk15ThreadPool.java
* created on 10.08.2006 by netseeker
* $Id: Jdk15ThreadPool.java,v 1.7 2006/11/10 00:35:14 netseeker Exp $
* $Log: Jdk15ThreadPool.java,v $
* Revision 1.7 2006/11/10 00:35:14 netseeker
* switched to maven2
*
* Revision 1.6 2006/11/05 16:34:39 netseeker
* Code cleanup, added support of JDK 1.5 thread pools
*
* Revision 1.5 2006/10/16 19:50:10 netseeker
* *** empty log message ***
*
* Revision 1.4 2006/10/11 22:40:31 netseeker
* *** empty log message ***
*
* Revision 1.3 2006/08/10 19:13:20 netseeker
* modified sources to be compatible to compiler java source level 1.4
*
* Revision 1.2 2006/08/10 18:57:06 netseeker
* *** empty log message ***
*
* Revision 1.1 2006/08/10 18:36:04 netseeker
* added abstraction of ThreadPools and an Executor based implementation for Java >= 1.5
*
*
* ====================================================================
*
* Copyright 2005-2006 netseeker aka Michael Manske
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.concurrent;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Fixed size thread pool implementation for usage with java >= 1.5.0
*
* @author netseeker
* @since 0.3.9.1
*/
public class Jdk15ThreadPool implements ThreadService
{
private ThreadPoolExecutor _execService;
/**
*
*/
public Jdk15ThreadPool()
{
this( 1 );
}
/**
* @param numberOfThreads
*/
public Jdk15ThreadPool(int numberOfThreads)
{
_execService = new ThreadPoolExecutor( numberOfThreads, numberOfThreads, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue(), new EJThreadFactory() );
}
/**
* @param threadGroup
*/
public Jdk15ThreadPool(final ThreadGroup threadGroup)
{
this( 1 );
}
/**
* @param threadGroup
* @param numberOfThreads
*/
public Jdk15ThreadPool(final ThreadGroup threadGroup, int numberOfThreads)
{
_execService = new ThreadPoolExecutor( numberOfThreads, numberOfThreads, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue(), new EJThreadFactory( threadGroup ) );
// _execService.prestartAllCoreThreads();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#getActiveWorkerCount()
*/
public int getActiveWorkerCount()
{
return _execService.getActiveCount();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#getCurrentPoolsize()
*/
public int getCurrentPoolsize()
{
return _execService.getPoolSize();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#getExpectedPoolsize()
*/
public int getExpectedPoolsize()
{
return _execService.getCorePoolSize();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#invokeLater(java.lang.Runnable)
*/
public void invokeLater( Runnable task )
{
_execService.execute( task );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#resize(int)
*/
public void resize( int poolSize )
{
_execService.setMaximumPoolSize( poolSize );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.concurrent.ThreadService#stop()
*/
public void stop()
{
_execService.shutdown();
}
}