* fix possible cache startup race conditions
This commit is contained in:
parent
3ed18b5110
commit
c6433e5c81
|
@ -68,14 +68,6 @@ public class Main {
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String... arguments) {
|
public static void main(String... arguments) {
|
||||||
// initialize this stuff before anything else
|
|
||||||
initializeCache();
|
|
||||||
initializeSecurityManager();
|
|
||||||
|
|
||||||
// make sure tmpdir exists
|
|
||||||
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
|
||||||
tmpdir.mkdirs();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// parse arguments
|
// parse arguments
|
||||||
final ArgumentProcessor cli = new ArgumentProcessor();
|
final ArgumentProcessor cli = new ArgumentProcessor();
|
||||||
|
@ -92,6 +84,14 @@ public class Main {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize this stuff before anything else
|
||||||
|
initializeCache();
|
||||||
|
initializeSecurityManager();
|
||||||
|
|
||||||
|
// make sure tmpdir exists
|
||||||
|
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
|
tmpdir.mkdirs();
|
||||||
|
|
||||||
if (args.clearUserData()) {
|
if (args.clearUserData()) {
|
||||||
// clear preferences and cache
|
// clear preferences and cache
|
||||||
System.out.println("Reset preferences and clear cache");
|
System.out.println("Reset preferences and clear cache");
|
||||||
|
@ -104,6 +104,9 @@ public class Main {
|
||||||
}
|
}
|
||||||
Settings.forPackage(Main.class).clear();
|
Settings.forPackage(Main.class).clear();
|
||||||
CacheManager.getInstance().clearAll();
|
CacheManager.getInstance().clearAll();
|
||||||
|
|
||||||
|
// just clear all data and then exit
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set unixfs system property
|
// set unixfs system property
|
||||||
|
@ -338,10 +341,6 @@ public class Main {
|
||||||
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
|
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
|
||||||
*/
|
*/
|
||||||
private static void initializeCache() {
|
private static void initializeCache() {
|
||||||
// auto-shutdown ehcache
|
|
||||||
System.setProperty("net.sf.ehcache.enableShutdownHook", "true");
|
|
||||||
Logger.getLogger("net.sf.ehcache.CacheManager").setLevel(Level.OFF);
|
|
||||||
|
|
||||||
// prepare cache folder for this application instance
|
// prepare cache folder for this application instance
|
||||||
File cacheRoot = new File(getApplicationFolder(), "cache");
|
File cacheRoot = new File(getApplicationFolder(), "cache");
|
||||||
|
|
||||||
|
@ -364,15 +363,20 @@ public class Main {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
|
CacheManager.getInstance().shutdown();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore, shutting down anyway
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
lock.release();
|
lock.release();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString());
|
// ignore, shutting down anyway
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
handle.close();
|
handle.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString());
|
// ignore, shutting down anyway
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue