skiwi
skiwi

Reputation: 69249

Program encountering a file lock

I have written a Java application that has to monitor a live log file. However I have not thought of the possibly of the file being locked, and that is exactly the case now.

Is there a way to disable the ability to add filelocks in a directory under Windows? If I would succeed, what would happen to the program writing to the logs (I think it's written in C#).

I am suspecting the logger locks the file to prevent it from being deleted, I cannot see any reason why it would need to prevent reads on it.

Does anyone perhaps know another solution to "cancel" the read-part of a file lock from within Java, if that even makes sense?

Upvotes: 0

Views: 100

Answers (1)

C.Evenhuis
C.Evenhuis

Reputation: 26436

The entire idea of a lock is that when you acquire it, you have some sort of guarantee that you have exclusive access (of the desired type(s)) to the file. Perhaps the programmer of the other application made a mistake or did not give much thought to how he/she locked the file.

I don't think there are clean ways to bypass this problem (except hooking the OS calls?). You could open the file before running the other application, but chances are the application wouldn't even start up in that case.

Upvotes: 1

Related Questions