Guest User

Untitled

a guest
Jun 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. try {
  2. final Path lock = Files.write(PATH_TO_FILE_IN_A_CONSTANT, "Executing Job", StandardOpenOption.CREATE, StandardOpenOption.WRITE);
  3.  
  4. final RandomAccessFile raf = new RandomAccessFile(lock.toFile(), "r");
  5. FileLock fl = new FileInputStream(raf.getFD()).getChannel().lock(0, Long.MAX_VALUE, true);
  6. } catch (final IOException e) {
  7. LOGGER.error("Error while trying to write file. ERROR: " + e.getMessage(), e);
  8.  
  9. Runtime.getRuntime().exit(-1);
  10. }
Add Comment
Please, Sign In to add comment