2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.cbus.internal;
15 import java.util.HashMap;
17 import java.util.concurrent.ExecutorService;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.common.ThreadPoolManager;
23 import com.daveoxley.cbus.CGateThreadPool;
24 import com.daveoxley.cbus.CGateThreadPoolExecutor;
27 * The {@link CBusThreadPool} is responsible for executing jobs from a threadpool
29 * @author John Harvey - Initial contribution
32 public class CBusThreadPool extends CGateThreadPool {
34 private final Map<String, CGateThreadPoolExecutor> executorMap = new HashMap<>();
37 protected synchronized CGateThreadPoolExecutor CreateExecutor(@Nullable String name) {
38 String nullSafeName = name == null || name.isEmpty() ? "_default" : name;
39 CGateThreadPoolExecutor executor = executorMap.get(nullSafeName);
40 if (executor == null) {
41 executor = new CBusThreadPoolExecutor(nullSafeName);
42 executorMap.put(nullSafeName, executor);
47 public class CBusThreadPoolExecutor extends CGateThreadPoolExecutor {
48 private final ExecutorService threadPool;
50 public CBusThreadPoolExecutor(@Nullable String poolName) {
51 threadPool = ThreadPoolManager.getPool("binding.cbus-" + poolName);
55 protected void execute(@Nullable Runnable runnable) {
56 if (runnable != null) {
57 threadPool.execute(runnable);