made LockFile reentrant (multiple locks on the same file can be acquired in the same JVM instance)
Some checks failed
CI / build (push) Has been cancelled

added argument file to JavaProcessBuilder
This commit is contained in:
2025-01-23 18:00:47 +08:00
parent d61cfc6ea7
commit cddd7889c7
8 changed files with 464 additions and 55 deletions

View File

@@ -0,0 +1,6 @@
module net.woggioni.jwo.lockfile.test {
requires net.woggioni.jwo;
requires static lombok;
exports net.woggioni.jwo.lockfile.test;
}

View File

@@ -0,0 +1,42 @@
package net.woggioni.jwo.lockfile.test;
import lombok.SneakyThrows;
import net.woggioni.jwo.LockFile;
import net.woggioni.jwo.Run;
import java.nio.file.Path;
import java.nio.file.Paths;
public class LockFileTestMain {
@SneakyThrows
private static void run(
Path lockfilePath,
boolean shared,
boolean keep
) {
Thread t = new Thread((Run)() -> {
try (AutoCloseable lockfile = LockFile.acquire(lockfilePath, shared)) {
while (keep) {
Thread.sleep(1000);
}
}
});
t.start();
try (AutoCloseable lockfile = LockFile.acquire(lockfilePath, shared)) {
while (keep) {
Thread.sleep(1000);
}
}
t.join();
}
@SneakyThrows
public static void main(String[] args) {
Path lockfilePath = Paths.get(args[0]);
boolean shared = Boolean.parseBoolean(args[1]);
boolean keep = Boolean.parseBoolean(args[2]);
run(lockfilePath, shared, keep);
}
}