001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.task;
018
019import java.time.Duration;
020
021import org.springframework.boot.context.properties.ConfigurationProperties;
022
023/**
024 * Configuration properties for task execution.
025 *
026 * @author Stephane Nicoll
027 * @since 2.1.0
028 */
029@ConfigurationProperties("spring.task.execution")
030public class TaskExecutionProperties {
031
032        private final Pool pool = new Pool();
033
034        /**
035         * Prefix to use for the names of newly created threads.
036         */
037        private String threadNamePrefix = "task-";
038
039        public Pool getPool() {
040                return this.pool;
041        }
042
043        public String getThreadNamePrefix() {
044                return this.threadNamePrefix;
045        }
046
047        public void setThreadNamePrefix(String threadNamePrefix) {
048                this.threadNamePrefix = threadNamePrefix;
049        }
050
051        public static class Pool {
052
053                /**
054                 * Queue capacity. An unbounded capacity does not increase the pool and therefore
055                 * ignores the "max-size" property.
056                 */
057                private int queueCapacity = Integer.MAX_VALUE;
058
059                /**
060                 * Core number of threads.
061                 */
062                private int coreSize = 8;
063
064                /**
065                 * Maximum allowed number of threads. If tasks are filling up the queue, the pool
066                 * can expand up to that size to accommodate the load. Ignored if the queue is
067                 * unbounded.
068                 */
069                private int maxSize = Integer.MAX_VALUE;
070
071                /**
072                 * Whether core threads are allowed to time out. This enables dynamic growing and
073                 * shrinking of the pool.
074                 */
075                private boolean allowCoreThreadTimeout = true;
076
077                /**
078                 * Time limit for which threads may remain idle before being terminated.
079                 */
080                private Duration keepAlive = Duration.ofSeconds(60);
081
082                public int getQueueCapacity() {
083                        return this.queueCapacity;
084                }
085
086                public void setQueueCapacity(int queueCapacity) {
087                        this.queueCapacity = queueCapacity;
088                }
089
090                public int getCoreSize() {
091                        return this.coreSize;
092                }
093
094                public void setCoreSize(int coreSize) {
095                        this.coreSize = coreSize;
096                }
097
098                public int getMaxSize() {
099                        return this.maxSize;
100                }
101
102                public void setMaxSize(int maxSize) {
103                        this.maxSize = maxSize;
104                }
105
106                public boolean isAllowCoreThreadTimeout() {
107                        return this.allowCoreThreadTimeout;
108                }
109
110                public void setAllowCoreThreadTimeout(boolean allowCoreThreadTimeout) {
111                        this.allowCoreThreadTimeout = allowCoreThreadTimeout;
112                }
113
114                public Duration getKeepAlive() {
115                        return this.keepAlive;
116                }
117
118                public void setKeepAlive(Duration keepAlive) {
119                        this.keepAlive = keepAlive;
120                }
121
122        }
123
124}