S
Stefan Z Camilleri
Hi
I am creating a singleton that shall be accessed by multiple threads,
possibly simultaneously... here is my code
public class FooEngine implements FooInterface {
private static final m_barElement;
public static FooInterface getBarInstance() {
synchronized (BarElement) {
if (null == m_barElement) m_barElement = new FooEngine();
}
return m_barElement;
}
}
Somehow I need to check if m_barElement is initialized... in C# I
generally check for null, yet in Java it seems as though I have to
explicitly initialize it to null... but this would then mean that I cannot
assign it to an instance later.
Setting it to an instance of FooEngine at declaration is not an option
since FooEngine requires lots of other preparatory work prior to it's
being instantiated.
So, my question is, how can I check if it has been initialized without
setting it to null?
I am creating a singleton that shall be accessed by multiple threads,
possibly simultaneously... here is my code
public class FooEngine implements FooInterface {
private static final m_barElement;
public static FooInterface getBarInstance() {
synchronized (BarElement) {
if (null == m_barElement) m_barElement = new FooEngine();
}
return m_barElement;
}
}
Somehow I need to check if m_barElement is initialized... in C# I
generally check for null, yet in Java it seems as though I have to
explicitly initialize it to null... but this would then mean that I cannot
assign it to an instance later.
Setting it to an instance of FooEngine at declaration is not an option
since FooEngine requires lots of other preparatory work prior to it's
being instantiated.
So, my question is, how can I check if it has been initialized without
setting it to null?