Author: nfilotto
Date: 2011-10-27 11:49:58 -0400 (Thu, 27 Oct 2011)
New Revision: 5115
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java
Log:
EXOJCR-1598: RepositoryCreationService.removeRepository doesn't free memory resources
associated with removed repository
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-10-27
15:45:29 UTC (rev 5114)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-10-27
15:49:58 UTC (rev 5115)
@@ -259,6 +259,18 @@
private final IndexerIoModeHandler modeHandler;
/**
+ * The shutdown hook
+ */
+ private final Thread hook = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ stopped = true;
+ }
+ };
+
+ /**
* The unique id of the workspace corresponding to this multi index
*/
final String workspaceId;
@@ -367,14 +379,16 @@
{
public Void run()
{
- Runtime.getRuntime().addShutdownHook(new Thread()
+ try
{
- @Override
- public void run()
- {
- stopped = true;
- }
- });
+ Runtime.getRuntime().addShutdownHook(hook);
+ }
+ catch (IllegalStateException e)
+ {
+ // can't register shutdown hook because
+ // jvm shutdown sequence has already begun,
+ // silently ignore...
+ }
return null;
}
});
@@ -1340,7 +1354,6 @@
*/
void close()
{
-
// stop index merger
// when calling this method we must not lock this MultiIndex, otherwise
// a deadlock might occur
@@ -1395,6 +1408,24 @@
modeHandler.removeIndexerIoModeListener(this);
indexUpdateMonitor.removeIndexUpdateMonitorListener(this);
this.stopped = true;
+ // Remove the hook that will stop the threads if they are still running
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>()
+ {
+ public Void run()
+ {
+ try
+ {
+ Runtime.getRuntime().removeShutdownHook(hook);
+ }
+ catch (IllegalStateException e)
+ {
+ // can't register shutdown hook because
+ // jvm shutdown sequence has already begun,
+ // silently ignore...
+ }
+ return null;
+ }
+ });
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java 2011-10-27
15:45:29 UTC (rev 5114)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java 2011-10-27
15:49:58 UTC (rev 5115)
@@ -46,6 +46,22 @@
protected final ConcurrentLinkedQueue<File> files = new
ConcurrentLinkedQueue<File>();
+ /**
+ * The shutdown hook
+ */
+ private final Thread hook = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ File file = null;
+ while ((file = files.poll()) != null)
+ {
+ PrivilegedFileHelper.delete(file);
+ }
+ }
+ };
+
public FileCleaner()
{
this(DEFAULT_TIMEOUT);
@@ -123,7 +139,24 @@
catch (Exception e)
{
}
-
+ // Remove the hook for final cleaning up
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>()
+ {
+ public Void run()
+ {
+ try
+ {
+ Runtime.getRuntime().removeShutdownHook(hook);
+ }
+ catch (IllegalStateException e)
+ {
+ // can't register shutdown hook because
+ // jvm shutdown sequence has already begun,
+ // silently ignore...
+ }
+ return null;
+ }
+ });
if (files != null && files.size() > 0)
log.warn("There are uncleared files: " + files.size());
@@ -170,22 +203,11 @@
// register shutdown hook for final cleaning up
try
{
- Runtime.getRuntime().addShutdownHook(new Thread()
- {
- @Override
- public void run()
- {
- File file = null;
- while ((file = files.poll()) != null)
- {
- PrivilegedFileHelper.delete(file);
- }
- }
- });
+ Runtime.getRuntime().addShutdownHook(hook);
}
catch (IllegalStateException e)
{
- // can't register shutdownhook because
+ // can't register shutdown hook because
// jvm shutdown sequence has already begun,
// silently ignore...
}
Show replies by date