This is a follow-up to my previous post about "thread safe and writing to a common file". I changed the code to include singleton. Here is sample
public class LogWriter {
private static LogWriter lw = new LogWriter(); private LogWriter() {} public static synchronized LogWriter getLogWriter() { if(lw == null) lw = new LogWriter(); return lw; }
private synchronized writeLog() { // open file // write file // close file } }
Does this work ? I guess in this case I don't need to put "synchronized" keyword for an "object" inside the "writeLog()" method, right ? This is because I ensure only one static global instance is created. Please help me verify it.
thanks lot.
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
Let's not have five different conversations about this, please. I'm closing this thread; follow-ups can go here. Thank you.
"I'm not back." - Bill Harding, Twister
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.