Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Not closing connections and statements Date: Sat, 13 Aug 2016 12:19:41 +0200 Organization: Decebal Computing Lines: 59 Message-ID: <871t1tkm2q.fsf@Equus.decebal.nl> References: <87shuakxjq.fsf@Equus.decebal.nl> <87k2fllkjf.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="18865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KmDqdZ+WKJ642EDgRhWuxVva27osHebc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:2ImhzqQSzGtx6ylm+dZojf3KQjA= sha1:ZUIZvwWRPUzM9/ZXlN3YkqmfvJg= Xref: csiph.com comp.lang.java.programmer:35300 On Saturday 13 Aug 2016 08:47 CEST, Marcel Mueller wrote: > On 12.08.16 23.55, Cecil Westerhof wrote: >> That is what I use yes. I just write one record an hour to log the >> memory usage of the application. But maybe I am going to log more >> in the future. > > If it is just for logging with auto commit I would not care much. > However, it might or might not be a good advice to intentionally > keep a DB connection idle for an hour. I would prefer to close the > connection after each log write. In this scenario your question is > pointless. I have thought about opening and closing every time, but for the moment I decided against it. > But as already mentioned, log4j might be a good advice. But from my > experience any logging to a database is at most the second-best > solution. In critical situations it might not be reliable enough and > you loose exactly the log records that you really need. Of course, > it depends on your use case. Logging only once an hour might not > fall into this category. At the moment it is just to have some easily accessible information about the memory usage of the applications. I think it would be rare to loose a record, but even when that happens that would not be very big disaster. I did work a little bit with log4j, but it never hurts to deepen my knowledge of it. >> It works great: it is much better to get you log information out of >> a (SQLite) database as from different files. > > As soon as your program runs twice for some reason, you might think > different. ;-) That is why I also but the PID in the record. ;-) > However, appending to the same file from different JVMs portably and > atomically is also a challenge, albeit possible in Java. I just used Bash redirection. And once it went wrong because I used the same file. > The library also handles switching the logs from time to time to > limit their size as well as the cleanup of old logs. So no disk will > get full after years, because no one cleaned up the logs. In That is very easy to do with SQLite. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof