开发者

Why is my program creating empty .lck files?

开发者 https://www.devze.com 2022-12-28 14:27 出处:网络
I am trying to use Java Logger.I get my logger file (name.log) with the content, it works and I also get an empty name.log.lck 开发者_StackOverflowfile.

I am trying to use Java Logger. I get my logger file (name.log) with the content, it works and I also get an empty name.log.lck 开发者_StackOverflowfile.

Why does this file appear, what program is creating them and how I can remove this behavior?


.lck is used by the handler(file handler) to lock the file in order to delete this file. You need to close the Handler that is associated with that logger object before you close your program.

Here is sample lines how you can close associated handler:

for(Handler h:log.getHandlers())
{
    h.close();   //must call h.close or a .LCK file will remain.
}


lock files are commonly used in Unix/Linux to ensure exclusive or serial access to an important resource.

In this case, the resource is the log file itself--you wouldn't want two or more logger instances trying to write to the same log file at the same time. That would not work out well at all. More about file locking

As Peter Barrett says about the Java Logger:

When the log file is created, a separate lock file called (in your case) "dbslogfile.txt.lck" is also created. The Logger uses this as a mutual exclusion mechanism for access to the actual log file.


".lck" sounds suspiciously like a lock file. You didn't say which logger you use but at elast one of them uses .lck files for locks - see this reply:

When the log file is created, a separet lock file called (in your case) "dbslogfile.txt.lck" is also created. The Logger uses this as a mutual exclusion mechanism for access to the actual log file. It doesn't seem to have been able to create it (it would have to create the lock file before the log file, of course).


Why are there .LCK files hanging around?

In Linux I had these .LCK files:

> ls -l
-rw-r--r--  1 el el 4810 Feb  9  2013 mybackground.gif
-rw-r--r--  1 el el   33 Feb  9  2013 mybackground.gif.LCK
-rwxr--r--  1 el el  193 Feb  9  2013 my_file.html
-rw-r--r--  1 el el   33 Feb  9  2013 my_file.html.LCK

Some program is creating these files. You have to find out which one it is. The program doing this will be a program that tries to do some kind of operation on these files across a network or perhaps even on this disk. A poorly written program that synchronizes, copies or deletes files on a disk might elect to use lock files in its operation.

My lock file contained the following information:

eric||my.myemail@hotmail.com

It is safe to remove .LCK files once the the irresponsible process that left them open has exited. The purpose of these files is to make sure two processes doing the same thing don't step on each other causing errors.

The usage of .LCK files is a poor programming practice violating the rule of "don't second guess yourself". Creating code that does redundant things just to make triple sure we did it right is a sign you are a bad programmer.

Any program caught red handed littering these .LCK files hanging around should be judged negatively with extreme prejudice.

In my case, it was a "DreamWeaver CS4 auto-synchronize" operation that was creating and leaving open these files. You'll have to delete these files by hand, and then figure out what action is causing these files to be left open, then submit bug reports to fix that software.

0

精彩评论

暂无评论...
验证码 换一张
取 消