Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35293

Re: Not closing connections and statements

From Marcel Mueller <news.5.maazl@spamgourmet.org>
Newsgroups comp.lang.java.programmer
Subject Re: Not closing connections and statements
Date 2016-08-13 08:47 +0200
Organization MB-NET.NET for Open-News-Network e.V.
Message-ID <nomfpc$t30$1@gwaiyur.mb-net.net> (permalink)
References <87shuakxjq.fsf@Equus.decebal.nl> <nol6er$gf5$1@dont-email.me> <87k2fllkjf.fsf@Equus.decebal.nl>

Show all headers | View raw


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.

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.


> I heard a few times that it was very bad when your program terminates
> without closing. I thought it a little bit strange: but better save as
> sorry, that is why I wanted to check.

/Terminating/ without closing is no big deal. Almost any existing 
operating system will clean up resources in this case. And almost any 
database will simply rollback any incomplete transaction.

> 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. ;-)
However, appending to the same file from different JVMs portably and 
atomically is also a challenge, albeit possible in Java.

In our company we ended up to do almost all logging into simple CSV 
files with a robust format that cannot be compromised if someone 
accidentally logs binary content.
We wrote a small library for this purpose and ported it to at least 
half-dozen programming languages. So any application can log in a 
thread-safe and atomic way to a log file (or in fact anything else as 
well), even if two applications or instances write to the same log for 
some reason. It is similar to log4j and in fact also usable as appender 
but with more features.
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 contrast to log4j 
files will never get renamed because this could confuse concurrently 
reading applications or even cause locks (depending on the OS and file 
system). Instead we use (partial) time-stamps in the log name, e.g. the 
date in yyyymmdd format.

A reader application can browse this log files similarly to a database, 
including group by operations, parametric search and Regex search. The 
reader uses a small in memory database with deduplication, so even many 
logs with millions of entries can be searched in only a few seconds 
without much system resources.

Because of the common format of all these logs it turned out to be 
straight forward to write another small applications which scans all 
servers for theses logs and this way get simple usage statistics about 
all these applications and an overview of all used instances with a link 
to their logs using the reader above.


Marcel

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-12 13:59 +0200
  Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 09:15 -0400
    Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 09:39 -0400
    Re: Not closing connections and statements Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-12 22:31 +0200
      Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 22:04 -0400
        Re: Not closing connections and statements Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-13 07:55 +0200
  Re: Not closing connections and statements Martin Gregorie <martin@address-in-sig.invalid> - 2016-08-12 19:01 +0000
    Re: Not closing connections and statements Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-12 22:35 +0200
      Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 21:52 -0400
    Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-12 23:55 +0200
      Re: Not closing connections and statements Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-12 18:16 -0400
        Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 01:19 +0200
          Re: Not closing connections and statements Martin Gregorie <martin@address-in-sig.invalid> - 2016-08-13 00:21 +0000
            Re: Not closing connections and statements Gunter Herrmann <gunter.herrmann@earthlink.net> - 2016-08-17 16:38 -0400
      Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 21:58 -0400
        Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 12:50 +0200
      Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 21:59 -0400
      Re: Not closing connections and statements Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-13 08:47 +0200
        Re: Not closing connections and statements Andreas Leitgeb <avl@logic.at> - 2016-08-13 08:05 +0000
          Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 12:21 +0200
          Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-13 09:54 -0400
        Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 12:19 +0200
        Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-13 10:04 -0400
          log4j RollingFileAppender (was: Not closing connections and statements) Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-14 22:24 +0200
            Re: log4j RollingFileAppender Arne Vajhøj <arne@vajhoej.dk> - 2016-08-14 21:01 -0400
        Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-13 11:58 -0400
          logging (was: Not closing connections and statements) Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-14 23:46 +0200
    Re: Not closing connections and statements Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 21:44 -0400
  Re: Not closing connections and statements Florian Weimer <fw@deneb.enyo.de> - 2016-08-13 16:33 +0200
    Re: Not closing connections and statements Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 17:34 +0200

csiph-web