]> source.dussan.org Git - archiva.git/commitdiff
shutdown executor service on close
authorolivier lamy <olamy@apache.org>
Mon, 31 Jul 2017 12:16:08 +0000 (22:16 +1000)
committerolivier lamy <olamy@apache.org>
Mon, 31 Jul 2017 12:16:08 +0000 (22:16 +1000)
Signed-off-by: olivier lamy <olamy@apache.org>
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/RepositoryFactory.java
archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java

index e2be03f4017e2febf48387954a0f91fb8d00b34b..c02e71f76c08e5aba556ca0cf146dbe4cad628e7 100644 (file)
@@ -77,20 +77,22 @@ public class RepositoryFactory
 
     private FileStore fileStore;
 
+    private ExecutorService executorService;
+
     public enum StoreType
     {
         SEGMENT_FILE_TYPE,
         IN_MEMORY_TYPE;
     }
 
-
     private StoreType storeType = SEGMENT_FILE_TYPE;
 
-    Path repositoryPath = Paths.get( "repository" );
+    private Path repositoryPath = Paths.get( "repository" );
 
     public Repository createRepository()
         throws IOException, InvalidFileStoreVersionException
     {
+        createExecutor();
         NodeStore nodeStore;
         if ( SEGMENT_FILE_TYPE == storeType )
         {
@@ -199,7 +201,6 @@ public class RepositoryFactory
             }
         } );
 
-        ExecutorService executorService = createExecutor();
         StatisticsProvider statsProvider = StatisticsProvider.NOOP;
         int queueSize = Integer.getInteger( "queueSize", 10000 );
         File indexDir = Files.createTempDirectory( "archiva_index" ).toFile();
@@ -255,6 +256,10 @@ public class RepositoryFactory
         {
             fileStore.close();
         }
+        if (executorService != null)
+        {
+            executorService.shutdownNow();
+        }
     }
 
     public StoreType getStoreType()
@@ -294,9 +299,13 @@ public class RepositoryFactory
         }
     }
 
-    private ExecutorService createExecutor()
+    private void createExecutor()
     {
-        return Executors.newCachedThreadPool();
+        if (executorService ==null )
+        {
+            executorService = Executors.newCachedThreadPool();
+        }
+
 //
 //        ThreadPoolExecutor executor =
 //            new ThreadPoolExecutor( 0, 5, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
index 6094a631c7a2ef135ffc964582ceadbfac9670f6..52f37b4ffe31d57740a4b48ed747cc8c6e8bdf16 100644 (file)
@@ -84,7 +84,9 @@ public class JcrRepositoryStatisticsGatheringTest
 
         RepositoryFactory repositoryFactory = new RepositoryFactory();
         repositoryFactory.setRepositoryPath( dir.getPath() );
-        session = repositoryFactory.createRepository().login(new SimpleCredentials( "admin", "admin".toCharArray()));
+        repositoryFactory.setStoreType( RepositoryFactory.StoreType.IN_MEMORY_TYPE );
+        session = repositoryFactory.createRepository() //
+            .login(new SimpleCredentials( "admin", "admin".toCharArray()));
 
 
         // TODO: perhaps have an archiva-jcr-utils module shared by these plugins that does this and can contain