001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.spi;
018    
019    import java.util.concurrent.ExecutorService;
020    import java.util.concurrent.ScheduledExecutorService;
021    import java.util.concurrent.ThreadFactory;
022    
023    /**
024     * Creates ExecutorService and ScheduledExecutorService objects that work with a thread pool for a given ThreadPoolProfile and ThreadFactory.
025     * 
026     * This interface allows to customize the creation of these objects to adapt camel for application servers and other environments where thread pools
027     * should not be created with the jdk methods
028     */
029    public interface ThreadPoolFactory {
030    
031        /**
032         * Creates a new cached thread pool
033         * <p/>
034         * The cached thread pool is a term from the JDK from the method {@link java.util.concurrent.Executors#newCachedThreadPool()}.
035         * Typically it will have no size limit (this is why it is handled separately
036         *
037         * @param threadFactory factory for creating threads
038         * @return the created thread pool
039         */
040        ExecutorService newCachedThreadPool(ThreadFactory threadFactory);
041        
042        /**
043         * Create a thread pool using the given thread pool profile
044         * 
045         * @param profile parameters of the thread pool
046         * @param threadFactory factory for creating threads
047         * @return the created thread pool
048         */
049        ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory);
050        
051        /**
052         * Create a scheduled thread pool using the given thread pool profile
053         * @param profile parameters of the thread pool
054         * @param threadFactory factory for creating threads
055         * @return the created thread pool
056         */
057        ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory);
058    }