I have noticed that a message appears in the console. It outputs this message to my terminal every few seconds. I have tried to close the console but it was immediately open with this message. This is something I had not noticed before and only started happening within the past few days. My Fiji installation is up to date, I am using version 2.03/1.53r/Java1.80_172.
I don’t seem to have any operational issues with Fiji.
> Apr 27, 2022 9:27:59 AM java.util.prefs.FileSystemPreferences syncWorld
> WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
@albertcardona @axtimwalde @ctrueden
We are getting the same message and, even though it states it is a WARNING, in fact it does seem to kill the process:
Any ideas?
Probably important: Using nextflow, we are running several Fiji in parallel on the same machine…
@Wayne do you think this error could be due to two instances of ImageJ accessing the same IJ_Prefs.txt file at the same time?
Wayne
(Wayne Rasband)
4
Hi @Christian_Tischer,
This is not an ImageJ error. ImageJ does not use java.util.prefs.
Thanks!
Just in case, is there a way to specify a folder for IJ_Prefs.txt via the command line during startup of Fiji?
Wayne
(Wayne Rasband)
6
Hi @Christian_Tischer,
ImageJ looks for the IJ_Prefs.txt file in the current directory, in the ImageJ directory and in home directory, it that order.
This is what the code (in Prefs.java) looks like:
public static String getPrefsDir() {
// look in current directory
if (prefsDir==null) {
String cwd = System.getProperty("user.dir");
File f = new File(cwd+File.separator+PREFS_NAME);
if (f.exists()) {
prefsDir = cwd;
preferencesPath = cwd+"/"+PREFS_NAME;
}
// look in ImageJ directory
if (prefsDir==null) {
String ijDir = getImageJDir();
ijDir = ijDir.substring(0, ijDir.length()-1);
f = new File(ijDir+File.separator+PREFS_NAME);
if (f.exists()) {
prefsDir = ijDir;
preferencesPath = ijDir+"/"+PREFS_NAME;
}
}
// use home directory
if (prefsDir==null) {
String dir = System.getProperty("user.home");
if (IJ.isMacOSX())
dir += "/Library/Preferences";
else
dir += File.separator+".imagej";
prefsDir = dir;
}
}
return prefsDir;
}
Thanks! That may be a way… in a compute cluster context, for each job one could create a folder with a IJ_Prefs.txt file and start ImageJ there.
Is the solution here to make a .txt file with this code place it in the working directory?
ctrueden
(Curtis Rueden)
9
@Christian_Tischer Just to second @Wayne’s point: the Java Preferences usage comes from ImageJ2, not the original ImageJ. So whatever you do with IJ_Prefs.txt will not save you! 
I am afraid that this error:
Is simply a bug which needs to be fixed. The only way I know to avoid it in the current codebase would be to write your own PrefService implementation with higher priority than the DefaultPrefService and override how the preference loading/saving works. Unless someone can figure out why Java does not have write access to the user’s Java Preferences space with certain system configurations…
@tpietzsch at one point threatenedconsidered to spend time rewriting PrefService to use YAML instead of Java Preferences, because quite some folks over the years have run into these sorts of problems with it, but I believe he ended up not having time to do it, and instead people just choose not to use the SciJava PrefService in favor of rolling their own preferences logic ad hoc, which is a shame.
There is not currently a dedicated issue on Issues · scijava/scijava-common · GitHub tracking this BackingStoreException problem, although it is mentioned among several problems in Script Interpreter issues · Issue #308 · scijava/scijava-common · GitHub. If you would care to file a dedicated issue for it, that would be appreciated.
ctrueden
(Curtis Rueden)
10
@bluemonkey12 Thanks for the report. Have you tried a newer version of Java 8 or Java 11? This bug in Java might be fixed.
I created an issue: BackingStoreException caused by PrefService · Issue #440 · scijava/scijava-common · GitHub
@ctrueden do you think this would be worth exploring?
(found at: preferences - java.util.Prefs throwing BackingStoreException - Why? - Stack Overflow)
I ran into the same issue with jetty. I found the following fixed the issue.
Add a .systemPrefs to your JRE directory and provide access to the user who is running the process which is complaining.
Once that is done, go to the Jetty directory and open the start.ini file
-Djava.util.prefs.userRoot={user's home directory}
-Djava.util.prefs.systemRoot={user's home directory}
Once finished adding those lines I restarted jetty and found that the errors were gone.
I think we could pass those variables to Fiji when starting from CLI?!
ctrueden
(Curtis Rueden)
12
@Christian_Tischer Yes, I think that workaround would be worth a try, at least until we have time to reimplement the PrefService to use YAML instead of Java Preferences. I saw you already linked it from the issue, thanks for that.