Commit ffc9294 1 parent af6addf commit ffc9294 Copy full SHA for ffc9294
File tree 2 files changed +24
-0
lines changed
api/src/main/java/org/openmrs/util
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 14
14
package org .openmrs .util ;
15
15
16
16
import java .lang .reflect .Field ;
17
+ import java .util .Map ;
17
18
import java .util .Timer ;
18
19
19
20
import org .apache .commons .logging .Log ;
20
21
import org .apache .commons .logging .LogFactory ;
22
+ import org .hibernate .impl .SessionFactoryObjectFactory ;
21
23
22
24
import sun .net .www .http .HttpClient ;
23
25
import sun .net .www .http .KeepAliveCache ;
@@ -81,4 +83,24 @@ public static void shutdownKeepAliveTimer() {
81
83
log .error (e .getMessage (), e );
82
84
}
83
85
}
86
+
87
+ /**
88
+ * Clears the hibernate session factories cached in the SessionFactoryObjectFactory
89
+ */
90
+ public static void clearHibernateSessionFactories () {
91
+ try {
92
+ Field field = SessionFactoryObjectFactory .class .getDeclaredField ("INSTANCES" );
93
+ field .setAccessible (true );
94
+ Map instances = (Map ) field .get (null );
95
+ instances .clear ();
96
+
97
+ field = SessionFactoryObjectFactory .class .getDeclaredField ("NAMED_INSTANCES" );
98
+ field .setAccessible (true );
99
+ Map namedInstances = (Map ) field .get (null );
100
+ namedInstances .clear ();
101
+ }
102
+ catch (Exception ex ) {
103
+ log .error (ex .getMessage (), ex );
104
+ }
105
+ }
84
106
}
Original file line number Diff line number Diff line change @@ -323,6 +323,8 @@ public static void destroyInstance() {
323
323
log .error (ex .getMessage (), ex );
324
324
}
325
325
}
326
+
327
+ MemoryLeakUtil .clearHibernateSessionFactories ();
326
328
327
329
OpenmrsClassScanner .destroyInstance ();
328
330
You can’t perform that action at this time.
0 commit comments