Using ThreadGroup for logging

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using ThreadGroup for logging

Mike Quilleash -2
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 framework.
 
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


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Using ThreadGroup for logging

Joe Bowbeer
On 7/24/06, Mike Quilleash <[hidden email]> wrote:
>
> 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 don't see an issue with what you're doing, though we have been
trying to slowly obsolete ThreadGroup..

For an alternative, see section on "Using ThreadLocal to simplify
debug logging" in Threading Lightly, part 3:

http://www-128.ibm.com/developerworks/java/library/j-threads3.html

An InheritableThreadLocal would pass the log from parent to child.

I can't think of a great reason to switch to ThreadLocal.

--Joe
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest