import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileLock; public class FileLockTest {
public static void main(String[] args) {
try (
var channel = new FileOutputStream("a.txt").getChannel())
{
FileLock flock = channel.lock();
Thread.sleep();
flock.release();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

learning java 文件锁的更多相关文章

  1. Learning Java language Fundamentals

    Chapter 2 Learning Java language fundamentals exercises: 1.What  is Unicode? Unicode is a computing ...

  2. blogs for learning java

    曹海成的专栏 http://blog.csdn.net/caohaicheng/article/details/38071097 http://blog.csdn.net/a5489888/artic ...

  3. Learning Java IO indexes

    I/O Streams, it simplifies I/O operations, write a whole object out to stream & read back. File ...

  4. Learning Java 8 Syntax (Java in a Nutshell 6th)

    Java is using Unicode set Java is case sensitive Comments, C/C++ style abstract, const, final, int, ...

  5. Learning Java characteristics (Java in a Nutshell 6th)

    Java characteristics: Java .class files are machine-independent, including the endianness. Java .cla ...

  6. [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java

    这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...

  7. learning java 使用WatchService监控文件变化

    import java.io.IOException; import java.nio.file.*; public class WatchServiceTest { public static vo ...

  8. learning java FileVisitor 遍丽文件及路径

    import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttribut ...

  9. learning java Paths Path

    import java.nio.file.Path; import java.nio.file.Paths; public class PathTest { public static void ma ...

随机推荐

  1. SAS学习笔记1

    数据采样 简单随机抽样,从sashelp数据集中air数据文件中选取30个数 数据探索 数字特征的探索:均值.频数.最大值.最小值.众数.中位数.方差.标准差 数字分布的探索:是否服从正态分布 连续型 ...

  2. 解决 Url is blocked: Requests to the local network are not allowed

    问题:         我在学习GitLab + Jenkins 自动化部署时,在GitLab的 MyProject => Settings => Integrations中输入完 &qu ...

  3. 高并发场景下System.currentTimeMillis()的性能问题的优化

    高并发场景下System.currentTimeMillis()的性能问题的优化 package cn.ucaner.alpaca.common.util.key; import java.sql.T ...

  4. SQL Server 隔离级别(RC&RR)

  5. tcp、udp协议栈

    tcp struct tcphdr { __be16 source; //源端口 __be16 dest; //目的端口 __be32 seq; //序列号 __be32 ack_seq; //确认号 ...

  6. 理解 Cookie,Session,Token 并结合 Redis 的使用

    Http 协议是一个无状态协议, 客户端每次发出请求, 请求之间是没有任何关系的.但是当多个浏览器同时访问同一服务时,服务器怎么区分来访者哪个是哪个呢? cookie.session.token 就是 ...

  7. php文字转语音

    使用百度接口 https://ai.baidu.com/docs#/TTS-Online-PHP-SDK/top 使用PHP SDK开发骤如下: 1.在官方网站下载php SDK压缩包. 2.将下载的 ...

  8. tmp-scmj

    1.apk下载 http://app6.wpf2x4.cn/?downloadfrom=sichuan 麻将图: Big_mahjonghn_tiles_sr.png

  9. weblogic如何修改密码&密码找回

    一.修改Console密码后,挂载的服务无法重启[解决办法] 1. 打开weblogic控制台,安全领域 --> myrealm --> 用户和组,将会看到weblogic用户,可以直接删 ...

  10. Linux实验:hdfs shell基本命令操作(二)

    [实验目的]    1)熟练hdfs shell命令操作    2)理解hdfs shell和linux shell命令[实验原理]    安装好hadoop环境之后,可以执行hdfs shell命令 ...