Skip to content

Commit

Permalink
BACKLOG-22955 : Create daemon threads for CarteStatusCache (pentaho#5293
Browse files Browse the repository at this point in the history
)

Use daemon threads to avoid blocking shutdown
  • Loading branch information
pentaho-apandit authored and Neeta Rathi committed Apr 24, 2018
1 parent 60b957a commit 8aa6598
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -36,14 +36,26 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;


public class CarteStatusCache implements Cache {

public static final String CARTE_STATUS_CACHE = "CARTE_CACHE";

private final ScheduledExecutorService removeService = Executors.newSingleThreadScheduledExecutor();
/**
* Switching the thread launched to be daemon otherwise it blocks the pentaho server shutdown
*/
private final ScheduledExecutorService removeService = Executors.newSingleThreadScheduledExecutor(
new ThreadFactory() {
public Thread newThread( Runnable r ) {
Thread t = Executors.defaultThreadFactory().newThread( r );
t.setDaemon( true );
t.setName( CarteStatusCache.class.getSimpleName() );
return t;
}
} );

private final Map<String, CachedItem> cachedMap = new ConcurrentHashMap<>();

Expand All @@ -53,7 +65,6 @@ public class CarteStatusCache implements Cache {

private TimeUnit timeUnit = null;


public static synchronized CarteStatusCache getInstance() {
if ( instance == null ) {
instance = new CarteStatusCache();
Expand All @@ -64,6 +75,7 @@ public static synchronized CarteStatusCache getInstance() {
private CarteStatusCache() {
period = Integer.parseInt( Const.getEnvironmentVariable( "CARTE_CLEAR_PERIOD", "1" ) );
timeUnit = TimeUnit.valueOf( Const.getEnvironmentVariable( "CARTE_CLEAR_TIMEUNIT", "DAYS" ) );

removeService.scheduleAtFixedRate( this::clear, 1, 1, TimeUnit.DAYS );
}

Expand Down

0 comments on commit 8aa6598

Please sign in to comment.