blob: 5c96d3b3c79682e9ccf3660d2900d44bccae92ac [file] [log] [blame]
Murat Parlakisikaf1042d2015-03-14 01:08:29 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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
17package org.onlab.util;
18
19
20import java.util.concurrent.ExecutorService;
21import java.util.concurrent.Executors;
22
23import static org.onlab.util.Tools.groupedThreads;
24
25/**
26 * SharedExecutors is designed to use thread pool for applications.
27 * SharedExecutors is recommended for applications instead of creating new thread groups.
28 */
29public final class SharedExecutors {
30
31 private static int numberOfThreads = 30;
32
33 private static ExecutorService singleThreadExecutor =
34 Executors.newSingleThreadExecutor(groupedThreads("onos/shared", "onos-single-executor"));
35
36 private static ExecutorService poolThreadExecutor =
37 Executors.newFixedThreadPool(numberOfThreads, groupedThreads("onos/shared", "onos-pool-executor-%d"));
38
39 private static java.util.Timer sharedTimer =
40 new java.util.Timer("onos-shared-timer");
41
42
43
44 private SharedExecutors() {
45
46 }
47
48 /**
49 * Returns the single thread executor.
50 *
51 * @return shared single thread executor
52 */
53 public static ExecutorService getSingleThreadExecutor() {
54 return singleThreadExecutor;
55 }
56 /**
57 * Returns the pool thread executor.
58 *
59 * @return shared executor pool
60 */
61 public static ExecutorService getPoolThreadExecutor() {
62 return poolThreadExecutor;
63 }
64 /**
65 * Returns the pool timer.
66 *
67 * @return shared timer
68 */
69 public static java.util.Timer getTimer() {
70 return sharedTimer;
71 }
72
73
74
75
76}