filelock

How safe is it to use Java FileLock?

跟風遠走 提交于 2021-01-24 07:53:05
问题 How safe is it to use java.nio.channels.FileLock for locking files among processes? It is stated that other processes can not access the file if we have an exclusive lock. However, the below answer on another SO question states other processes have to check for the filelock too in order for our process to be safe. (a) Are you aware that locking the file won't keep other processes from touching it unless they also use locks? So I tested my code and tried to change, a file which I have the lock

FileLock in Java doesn't work in Docke mount volume

六眼飞鱼酱① 提交于 2020-08-10 19:35:09
问题 In my situation, some web configuration files are shared through mount folder in Docker. In same cases we want to modify these files concurrently. That's why I want to use lock to make sure file is being modified once at the same time. But I found flock is not working in Docker. Does it not supported? public void modifyFile() { try { File file = new File("/tmp/fileToLock.dat"); // Creates a random access file stream to read from, and optionally to write to FileChannel channel = new

Java NIO基础知识整理(一)

社会主义新天地 提交于 2020-03-01 00:28:18
NIO 特性 1、 为原始类提供缓存支持; 2 、字符集编码解码解决方案; 3 、 Channel :一个新的原始 I/O 抽象; 4 、支持锁和内存映射文件的文件访问接口; 5 、提供多路非阻塞式( non-bloking )的高伸缩性网络 I/O 。 Buffer 在基本 I/O 操作中所有的操作都是直接以流的形式完成的,而在 NIO 中所有的操作都要使用到缓冲区处理,且所有的读写操作都是通过缓冲区完成的。缓冲区( Buffer )是一个线性的、有序的数据集,只能容纳某种特定的数据类型。 一个 Buffer 有以下几个属性: 容量( capacity ) :缓冲区能包含的元素的最大数目。 限制( limit ) :第一个无法被写入或读取的元素坐标。 坐标( position ) :下一个要写入或读取的元素的坐标。 更多 Buffer 的属性和方法参考 http://download.oracle.com/javase/6/docs/api/ 。 另外, http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ314_027.htm 上面有一个各种类型的 Buffer 和 byte[] 之间相互转换的模型图,挺有帮助的。 图 1 Buffer 内部结构 看一下一个简单的示例

DbContext doesn't release SQLite database

倖福魔咒の 提交于 2020-01-03 08:48:08
问题 First, these are my intentions: Create a DbContext on SQLite Read and write from/to it Close context Move the file to another location Points 1-3 work perfectly. The problem starts when I try to move the database. I get an error stating that: 'The process cannot access the file because it is being used by another process.' How can I resolve this? First, I create a context. I have to use it in several methods, and I don't want to create it every time I need it. So I am storing it as a member.

Concurrently write to XML file

谁说我不能喝 提交于 2019-12-31 02:58:11
问题 I have multiple processes running on different machines which are required to read/write to a shared XML file, for this I am using DOM with Java and FileLocks (While I know that a database would be a more effective approach, this is not viable due to project constraints) . To make changes to the XML file, the relevant process first creates an exclusively locked channel which is used to read the file, it then attempts to reuse the same channel to write the new version before closing the

Using FileChannel to write any InputStream?

和自甴很熟 提交于 2019-12-30 04:15:39
问题 Can I write any InputStream into a FileChannel? I'm using java.nio.channels.FileChannel to open a file and lock it, then writing a InputStream to the output file. The InputStream may be opened by another file, URL, socket, or anything. I've write the following codes: FileOutputStream outputStream = new FileOutputStream(outputFile); FileChannel outputChannel = outputStream.getChannel(); FileLock lock = outputChannel.lock(); try { outputChannel.transferFrom(???); } finally { lock.release();

Overwrite a properties file from the FileOutputStream obtained through FileDescriptor FD

蓝咒 提交于 2019-12-24 19:10:13
问题 Peculiar problem is When I am using the properties.store code with the FileOutputStream obtained from file path, the above method works all fine but when I do that from FileOutputStream obtained from FileDescriptor the properties file append to it, doesn't overwrite. Now my constraint is to use the later approach since I am using FileLock and cant get the FileOutputStream through file again. Is it possible? To do something with the later approach and overwrite and If not what are my options?

Disable locking of Neo4j graph database?

心已入冬 提交于 2019-12-23 05:22:43
问题 My application is populating a Neo4j graph database at /tmp/import.db . In addition to my unit tests I like to use the Neo4j browser (AKA Neo4j Community) to do some digging in that same database. When the browser is running, my application crashes when it gets run because the database it is locked: Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /tmp/import.db at org.neo4j.kernel.InternalAbstractGraphDatabase.run

How to find out what processes have folder or file locked?

∥☆過路亽.° 提交于 2019-12-20 21:47:13
问题 How do you go about querying running processes to find out what folders or files they have locked? (i.e. you go to eject a drive and you're told that it can't be ejected because it's in use) I'd like to either get an "off the shelf" download, or write a .NET 3.5 app to do this (primarily a Windows question). 回答1: Process Explorer will show you this. Ctrl-F will let you search for a file and list the process(es) that have that file open/locked. You can then close that handle using Process

Getting notified when a file lock is released

北慕城南 提交于 2019-12-20 02:56:15
问题 [Using C# and Windows as platform] I have a camera that writes JPG files to a local folder in my PC. I want to load each file the camera drops, so I have a FileSystemWatcher that notifies me whenever a new picture is created, but the camera locks the file while it's being written , so if I try to load it just after being notified of its creation, I get an exception saying that the file is locked . Currently, I have a while loop (with a Thread.Sleep) that retries to load the image every 0.2