Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1016917 // Test File Locking (OK on Windows and Linux)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1554L/11K).

!7

import java.nio.channels.*;
import java.nio.file.*;

p {
  File path = programFile("lockfile");
  FileChannel channel = FileChannel.open(toPath(path), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
  repeat with sleep 1 {
    {
      temp FileLock lock = channel.tryLock();
      if (lock == null) print("Couldn't lock.");
      else { print("Locked!"); sleepSeconds(1); }
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, ayokdxtdmvtg, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016917
Snippet name: Test File Locking (OK on Windows and Linux)
Eternal ID of this version: #1016917/7
Text MD5: a3e1b802722cba98606a2f6072bbbe67
Transpilation MD5: 095921415ffa1df0834ef8526ec47d19
Author: stefan
Category: javax / io
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-07 20:51:46
Source code size: 410 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 396 / 829
Version history: 6 change(s)
Referenced in: [show references]