jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1594205 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
Date Tue, 13 May 2014 12:01:27 GMT
Author: mduerig
Date: Tue May 13 12:01:26 2014
New Revision: 1594205

URL: http://svn.apache.org/r1594205
Log:
OAK-1815: Don't create default (Scheduled)Executor when respective instance is supplied
Create executor service instances only when needed

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1594205&r1=1594204&r2=1594205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Tue May
13 12:01:26 2014
@@ -129,9 +129,9 @@ public class Oak {
 
     private SecurityProvider securityProvider;
 
-    private ScheduledExecutorService scheduledExecutor = defaultScheduledExecutor();
+    private ScheduledExecutorService scheduledExecutor;
 
-    private Executor executor = defaultExecutorService();
+    private Executor executor;
 
     /**
      * Default {@code ScheduledExecutorService} used for scheduling background tasks.
@@ -187,6 +187,20 @@ public class Oak {
         return executor;
     }
 
+    private synchronized ScheduledExecutorService getScheduledExecutor() {
+        if (scheduledExecutor == null) {
+            scheduledExecutor = defaultScheduledExecutor();
+        }
+        return scheduledExecutor;
+    }
+
+    private synchronized Executor getExecutor() {
+        if (executor == null) {
+            executor = defaultExecutorService();
+        }
+        return executor;
+    }
+
     private MBeanServer mbeanServer;
 
     private String defaultWorkspaceName = DEFAULT_WORKSPACE_NAME;
@@ -216,7 +230,7 @@ public class Oak {
 
             final Closer observerSubscription = Closer.create();
             Future<?> future = null;
-            if (scheduledExecutor != null && type == Runnable.class) {
+            if (type == Runnable.class) {
                 Runnable runnable = (Runnable) service;
                 Long period = getValue(properties, "scheduler.period", Long.class);
                 if (period != null) {
@@ -224,10 +238,10 @@ public class Oak {
                             properties, "scheduler.concurrent",
                             Boolean.class, Boolean.FALSE);
                     if (concurrent) {
-                        future = scheduledExecutor.scheduleAtFixedRate(
+                        future = getScheduledExecutor().scheduleAtFixedRate(
                                 runnable, period, period, TimeUnit.SECONDS);
                     } else {
-                        future = scheduledExecutor.scheduleWithFixedDelay(
+                        future = getScheduledExecutor().scheduleWithFixedDelay(
                                 runnable, period, period, TimeUnit.SECONDS);
                     }
                 }
@@ -492,7 +506,7 @@ public class Oak {
     }
 
     public ContentRepository createContentRepository() {
-        whiteboard.register(Executor.class, executor, Collections.emptyMap());
+        whiteboard.register(Executor.class, getExecutor(), Collections.emptyMap());
 
         IndexEditorProvider indexEditors = CompositeIndexEditorProvider.compose(indexEditorProviders);
         OakInitializer.initialize(store, new CompositeInitializer(initializers), indexEditors);
@@ -513,7 +527,8 @@ public class Oak {
 
             PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex(
                     new AsyncIndexUpdate("async-reindex", store, indexEditors,
-                            true), executor);
+                            true), getExecutor()
+            );
             registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class,
                     asyncPI, PropertyIndexAsyncReindexMBean.TYPE, name);
         }



Mime
View raw message