Author: elvisisking
Date: 2009-12-18 15:48:51 -0500 (Fri, 18 Dec 2009)
New Revision: 1459
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
Log:
DNA-598 Shutting down JcrEngine returns, but leaves idle threads running (preventing
shutdown of VM) for 60 seconds: The ExecutorService started by the
RepositoryObservationManager is now being shutdown when the JcrRepository is closed.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-12-18 19:16:43
UTC (rev 1458)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-12-18 20:48:51
UTC (rev 1459)
@@ -431,8 +431,7 @@
}
// Initialize the observer, which receives events from all repository sources
- this.repositoryObservationManager = new RepositoryObservationManager();
- repositoryObservable.register(this.repositoryObservationManager);
+ this.repositoryObservationManager = new
RepositoryObservationManager(repositoryObservable);
// Set up the system source ...
String systemSourceNameValue = this.options.get(Option.SYSTEM_SOURCE_NAME);
@@ -933,6 +932,8 @@
if (this.federatedSource != null) {
this.federatedSource.close();
}
+
+ this.repositoryObservationManager.shutdown();
}
/**
@@ -1186,8 +1187,14 @@
private final ExecutorService observerService =
Executors.newSingleThreadExecutor();
private final CopyOnWriteArrayList<Observer> observers = new
CopyOnWriteArrayList<Observer>();
+ private final Observable repositoryObservable;
- protected RepositoryObservationManager() {
+ /**
+ * @param repositoryObservable the repository library observable this observer
should register with
+ */
+ protected RepositoryObservationManager(Observable repositoryObservable) {
+ this.repositoryObservable = repositoryObservable;
+ this.repositoryObservable.register(this);
}
/**
@@ -1233,12 +1240,23 @@
}
/**
+ * Must be called to shutdown the service that is used to notify the observers.
+ */
+ void shutdown() {
+ synchronized (this) {
+ this.repositoryObservable.unregister(this);
+ this.observers.clear();
+ this.observerService.shutdown();
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see
org.jboss.dna.graph.observe.Observable#unregister(org.jboss.dna.graph.observe.Observer)
*/
public boolean unregister( Observer observer ) {
- CheckArg.isNotNull(observer, "observer");
+ if (observer == null) return false;
return this.observers.remove(observer);
}
}
Show replies by date