概述
release()FileChannel性质
排它锁
进程对某文件上锁后,其他进程不能读写此文件
共享锁
进程对某文件上锁后,其他进程可以读取此文件
方法
加锁
lock()
lock(position,size,shared)
tryLock()
tryLock(position,size,shared)
解锁
release()
示例
public void filelock(String filePath){
try (
FileChannel channel = FileChannel.open(Paths.get(filePath), StandardOpenOption.WRITE,StandardOpenOption.APPEND);
BufferedReader bf = new BufferedReader(new FileReader(filePath));
){
ByteBuffer buf = ByteBuffer.wrap("0123456789".getBytes(StandardCharsets.UTF_8));
FileLock lock = channel.lock();
channel.write(buf);
lock.release();
String line = null;
while((line = bf.readLine()) != null){
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
简介
Redis ACL = Access Control List,访问控制表
ACL 相当于一套权限控制,从下面维度控制连接
flushb、shutown、keys *设置
acl setuser user_name on >password ~key_express +command