#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:
Denny
2017-01-22 09:33:47 -05:00
parent 523ac0314e
commit 6e94d9ce51
39 changed files with 8822 additions and 9118 deletions

View File

@@ -1,113 +0,0 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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 controller;
import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ThreadPoolManager
{
private final static Logger mLog = LoggerFactory.getLogger( ThreadPoolManager.class );
private int THREAD_POOL_SIZE = 2;
private HashMap<ScheduledFuture<?>,ThreadType> mTasks =
new HashMap<ScheduledFuture<?>,ThreadType>();
private ScheduledExecutorService mExecutor;
public ThreadPoolManager()
{
}
public ScheduledExecutorService getScheduledExecutorService()
{
if( mExecutor == null )
{
mExecutor = Executors.newScheduledThreadPool( THREAD_POOL_SIZE,
new NamingThreadFactory( "sdrtrunk" ) );
}
return mExecutor;
}
public ScheduledFuture<?> scheduleFixedRate( ThreadType type,
Runnable command,
long period,
TimeUnit unit )
throws RejectedExecutionException
{
ScheduledExecutorService executorService = getScheduledExecutorService();
ScheduledFuture<?> task =
executorService.scheduleAtFixedRate( command, 0, period, unit );
mTasks.put( task, type );
return task;
}
public void scheduleOnce( Runnable command, long delay, TimeUnit unit )
throws RejectedExecutionException
{
ScheduledExecutorService executorService = getScheduledExecutorService();
executorService.schedule( command, delay, unit );
}
public boolean cancel( ScheduledFuture<?> task )
{
boolean success = task.cancel( true );
mTasks.remove( task );
return success;
}
public int getTaskCount( ThreadType type )
{
int count = 0;
for( ThreadType current: mTasks.values() )
{
if( current == type )
{
count++;
}
}
return count;
}
public enum ThreadType
{
AUDIO_PROCESSING,
AUDIO_RECORDING,
BASEBAND_RECORDING,
SOURCE_SAMPLE_PROCESSING,
DECIMATION,
DECODER;
}
}