| Author |
Is there any way to close all existing file handlers when the java application ends?
|
cle tan
Ranch Hand
Joined: Jun 11, 2012
Posts: 68
|
|
As sometimes when the application ends, some of the logs will be xxx.log.1 , xxx.log.2
seems like the logs are still being locked.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
You would usually close files immediately after reading or writing, but I see that log files would stay open until the JVM exits.
Can you list all open files?
What about a shutdown hook which starts a new thread to close all those files?
|
 |
cle tan
Ranch Hand
Joined: Jun 11, 2012
Posts: 68
|
|
Assuming java application program ended, can it guarantee that a file won't be locked when it exits?
how to implement a shutdown hook?
|
 |
Ivan Jozsef Balazs
Ranch Hand
Joined: May 22, 2012
Posts: 445
|
|
Any decent operating system will free the resources held by a program upon its termination.
Exactly what kind of lock is it? Does it persist across the life span of a program?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
Shutdown hooks are really easy to use. If you search, you find lots of links, of which I am showing two: 1 2. I think no 1 is better.
|
 |
 |
|
|
subject: Is there any way to close all existing file handlers when the java application ends?
|
|
|