I am reading source code about the java.sql.DriverManager,and found something confusing.Here is the code:
static {
loadInitialDrivers();
println("JDBC DriverManager initialized");
}
......
public static void println(String message) {
synchronized (logSync) {
if (logWriter != null) {
logWriter.println(message);
// automatic flushing is never enabled, so we must do it ourselves
logWriter.flush();
}
}
}
The logWriter have not been set when class initialize,but was called by its static block.So I can't see any log info about this. How can I set field value before class initialization?
The only way is to set the
logWriter
in aDriver
implementation.Then you will get the log
EDIT
For @moilejter's question, here give a simple sample of how two classes call each other even they are both not ready.