Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java preferences: Could not lock User prefs. Lock file access denied

I'm running a Java Spark server on a Linux machine, and I'm trying to store user preferences and I'm having two major problems:

  1. While i can get/set preferences on runtime, The preferences are getting deleted each time I kill the program and run it again.

  2. Sometimes I receive this error (which might have to do with users requesting different pages on the same time):

    Exception in thread "Timer-0" java.lang.SecurityException: Could not lock User prefs. Lock file access denied.

My code looks like this:

...
prefs = Preferences.userRoot().node(PREFS_NAME);
...
get("/sample/reset", (req, res) -> {
    prefs.put("bgimg", "test");
    ...
});
get("/sample/", (req, res) -> {
    String bgImgPath = prefs.get("bgimg",BACKGROUND_IMAGE_PATH);
    ...
});
like image 221
OmriSoudry Avatar asked Dec 01 '25 11:12

OmriSoudry


1 Answers

I solved the issue with the following:

sudo chmod -R 775 ~/.java/
sudo chown -R username:root ~/.java/

Just doing the first command wasn't enough.

like image 58
inkalchemist1994 Avatar answered Dec 03 '25 00:12

inkalchemist1994



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!