KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > thread > DefaultThreadFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.thread;
17
18 /**
19  * This class is responsible to create new Thread instances to run a command.
20  *
21  * @author <a HREF="mailto:info@otego.com">Otego AG, Switzerland</a>
22  * @version $Id: DefaultThreadFactory.java 56765 2004-11-06 13:54:31Z giacomo $
23  */

24 public class DefaultThreadFactory
25     implements ThreadFactory, EDU.oswego.cs.dl.util.concurrent.ThreadFactory
26 {
27     //~ Instance fields --------------------------------------------------------
28

29     /** The daemon mode */
30     private boolean m_isDaemon = false;
31
32     /** The priority of newly created Threads */
33     private int m_priority = Thread.NORM_PRIORITY;
34
35     //~ Methods ----------------------------------------------------------------
36

37     /**
38      * Set the isDaemon property
39      *
40      * @param isDaemon Whether or not new <code>Thread</code> should run as
41      * daemons.
42      */

43     public void setDaemon( boolean isDaemon )
44     {
45         m_isDaemon = isDaemon;
46     }
47
48     /**
49      * Get the isDaemon property
50      *
51      * @return Whether or not new <code>Thread</code> will run as daemons.
52      */

53     public boolean isDaemon( )
54     {
55         return m_isDaemon;
56     }
57
58     /**
59      * Set the priority newly created <code>Thread</code>s should have
60      *
61      * @param priority One of {@link Thread#MIN_PRIORITY}, {@link
62      * Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
63      */

64     public void setPriority( final int priority )
65     {
66         if( ( Thread.MAX_PRIORITY == priority ) ||
67             ( Thread.MIN_PRIORITY == priority ) ||
68             ( Thread.NORM_PRIORITY == priority ) )
69         {
70             m_priority = priority;
71         }
72     }
73
74     /**
75      * Get the priority newly created <code>Thread</code>s will have
76      *
77      * @return One of {@link Thread#MIN_PRIORITY}, {@link
78      * Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
79      */

80     public int getPriority( )
81     {
82         return m_priority;
83     }
84
85     /**
86      * Create a new Thread for Runnable
87      *
88      * @param command The {@link Runnable}
89      *
90      * @return A new Thread instance
91      */

92     public Thread JavaDoc newThread( final Runnable JavaDoc command )
93     {
94         final Thread JavaDoc thread = new Thread JavaDoc( command );
95         thread.setPriority( m_priority );
96         thread.setDaemon( m_isDaemon );
97
98         return thread;
99     }
100 }
101
Popular Tags