what is the best way to write to a log from threads?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vinod_Kaggal
Posted On:   Sunday, October 7, 2001 02:20 PM

If I have two threads ThreadA and ThreadB which are created by another thread mainThread, what is the best way for ThreadA and ThreadB to write to the same log file?


Thanks in advance!

Re: what is the best way to write to a log from threads?

Posted By:   Bernard_Choi  
Posted On:   Sunday, October 7, 2001 09:42 PM



Logger logger = new Logger();

ThreadA threadA = new ThreadA(logger);
ThreadA threadB = new ThreadB(logger);



this way, both threads refer to the same logging object.

You can call logger.log() from either thread.

the Logger.log() method should be synchronized to avoid both threads trying to do a log at the same time.
About | Sitemap | Contact