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
Some checks failed
CI / build (push) Has been cancelled
added argument file to JavaProcessBuilder
This commit is contained in:
6
jwo-test/src/main/java/module-info.java
Normal file
6
jwo-test/src/main/java/module-info.java
Normal file
@@ -0,0 +1,6 @@
|
||||
module net.woggioni.jwo.lockfile.test {
|
||||
requires net.woggioni.jwo;
|
||||
requires static lombok;
|
||||
|
||||
exports net.woggioni.jwo.lockfile.test;
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user