mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
#108 [WIP] Created new ThreadPool class with a static ScheduledThreadExecutor that is now shared by all components. Removed ThreadPoolManager from all classes. Consolidating into 1 pool seems to have reduced CPU usage by ~15-20%. Overall memory usage is also reduced.
This commit is contained in:
54
src/util/ThreadPool.java
Normal file
54
src/util/ThreadPool.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package util;
|
||||
|
||||
import controller.NamingThreadFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class ThreadPool
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ThreadPool.class);
|
||||
|
||||
private static int CORES = Runtime.getRuntime().availableProcessors();
|
||||
public static ScheduledExecutorService SCHEDULED;
|
||||
|
||||
static
|
||||
{
|
||||
//Create a scheduled thread pool sized according to the available processors/cores, minimum 2
|
||||
CORES = (CORES < 2 ? 2 : CORES);
|
||||
|
||||
SCHEDULED = Executors.newScheduledThreadPool(CORES, new NamingThreadFactory("sdrtrunk"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Application-wide shared thread pools and scheduled executor service.
|
||||
*/
|
||||
public ThreadPool()
|
||||
{
|
||||
}
|
||||
|
||||
public static void logSettings()
|
||||
{
|
||||
mLog.info("Application thread pool created with [" + CORES + "] threads");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user