"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
actually, i am using SimpleDataSource class in ibatis, and it releases all database connections in its finalize method.
i'm surprised that all database connections disappear even if i kill the java process.
i'm not sure when and how it does the job. so i asked the question.
It is not recommended to close connections in finalizers because there is no guaranty that it will run.
Try adding a shutdownhook to the runtime.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
When you "kill" the java process and the DataSource connections are closed, it doesn't mean that the finalize method was called. And as Wouter said, there are no guarantees that finalize method will run, you should think about redesigning your logic so that you close the connection after your use is over...
I know there are no guarantees that finalize method will run, so I don' understand why when i killed the java process, all database connections disappeared.
i don't think SimpleDataSource class has the chance to close the connections.
zheng li wrote:
I know there are no guarantees that finalize method will run, so I don' understand why when i killed the java process, all database connections disappeared.
i don't think SimpleDataSource class has the chance to close the connections.
When a process terminates, the operating system frees all resources.
There is no need to run the GC because all allocated memory will be freed. There is no need to finalize the database connection, because the OS will close all files and network connections.
This is done for all applications, regardless of whether it is the JVM or not.
zheng li wrote:
I know there are no guarantees that finalize method will run, so I don' understand why when i killed the java process, all database connections disappeared.
i don't think SimpleDataSource class has the chance to close the connections.
When a process terminates, the operating system frees all resources.
There is no need to run the GC because all allocated memory will be freed. There is no need to finalize the database connection, because the OS will close all files and network connections.
This is done for all applications, regardless of whether it is the JVM or not.
Henry
thank you.
i met something on windows like after i terminate a program, i can't delete the file the program has modified. so i always thought that i couldn' rely on OS.
but now it seems OS does some cleanup for us.
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Gift giving made easy with the permaculture playing cards