Download Jar. Libraryless. Click here for Pure Java version (1554L/11K).
1 | !7 |
2 | |
3 | import java.nio.channels.*; |
4 | import java.nio.file.*; |
5 | |
6 | p { |
7 | File path = programFile("lockfile"); |
8 | FileChannel channel = FileChannel.open(toPath(path), StandardOpenOption.CREATE, StandardOpenOption.WRITE); |
9 | repeat with sleep 1 { |
10 | { |
11 | temp FileLock lock = channel.tryLock(); |
12 | if (lock == null) print("Couldn't lock."); |
13 | else { print("Locked!"); sleepSeconds(1); } |
14 | } |
15 | } |
16 | } |
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: | 596 / 1205 |
Version history: | 6 change(s) |
Referenced in: | [show references] |