de.hunsicker.util.concurrent.ThreadFactoryUser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jalopy Show documentation
Show all versions of jalopy Show documentation
A source code formatter/beautifier/pretty printer for the Java programming language.
The newest version!
/*
* Copyright (c) 2001-2002, Marco Hunsicker. All rights reserved.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*/
package de.hunsicker.util.concurrent;
/**
* Base class for Executors and related classes that rely on thread factories. Generally
* intended to be used as a mixin-style abstract class, but can also be used
* stand-alone.
*
*
* This class was taken from the util.concurrent package written by Doug Lea. See http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
* for an introduction to this package.
*
*
* @author Doug Lea
*/
public class ThreadFactoryUser
{
//~ Instance variables ---------------------------------------------------------------
/** DOCUMENT ME! */
protected ThreadFactory threadFactory_ = new DefaultThreadFactory();
//~ Methods --------------------------------------------------------------------------
/**
* Set the factory for creating new threads. By default, new threads are created
* without any special priority, threadgroup, or status parameters. You can use a
* different factory to change the kind of Thread class used or its construction
* parameters.
*
* @param factory the factory to use
*
* @return the previous factory
*/
public synchronized ThreadFactory setThreadFactory(ThreadFactory factory)
{
ThreadFactory old = threadFactory_;
threadFactory_ = factory;
return old;
}
/**
* Get the factory for creating new threads.
*
* @return DOCUMENT ME!
*/
public synchronized ThreadFactory getThreadFactory()
{
return threadFactory_;
}
//~ Inner Classes --------------------------------------------------------------------
protected static class DefaultThreadFactory
implements ThreadFactory
{
public Thread newThread(Runnable command)
{
return new Thread(command);
}
}
}