[concurrency-interest] Using ThreadGroup for logging
mike.quilleash at subexazure.com
Mon Jul 24 06:51:11 EDT 2006
I have read about ThreadGroups and I have found a use for them to solve
a problem I had. I'd appreciate any comment on whether this is good/bad
and whether there is a better way as I have read that ThreadGroups are
bad, but this may just be because of stop/suspend etc and other dodgy
statistic functions that it supports.
I have a program that spawns indivudual tasks, each of which is designed
to do some piece of work. Each task has a separate log file for logging
it's progress/error messages etc using Log4J. The problem I have is
that these tasks use a fair few lower-level libraries which do logging
and I would like to trap the log messages from these libraries in the
task log. To compound the issue sometimes these tasks create child
threads which use these libraries. I want to avoid passing a Log object
around, especially into the libraries, and similarly don't want the
libraries calling out and fetching a the log from elsewhere.
So I came up with the idea of for each task creating a ThreadGroup and
the create the main task thread on this ThreadGroup (I don't use thread
pooling). I then use a Log4J file appender to link to the task log and
add a filter for this appender to only accept messages from threads that
belong to the task ThreadGroup. This way library functions can call
standard logging functions and messages get routed to the relevant task
logs by Thread(Group) without them having to know about the task
Appreciate any feedback/comments/better ideas.
This e-mail is bound by the terms and conditions described at http://www.subexazure.com/mail-disclaimer.html
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest