问题
For some strange reason, I have a line of code that is getting stuck in an infinite loop. This is the line:
this.logger = LogManager.getLogger(getClass().getName());
A little context might be helpful:
I have a machine that stores all the code and java .class files. I access this machine through sshfs and work directly on the .java files through Eclipse.
If I login in the remote machine and execute my class, the code runs:
$ ssh remote-machine
$ cd /path/to/eclipse-project
$ export CLASSPATH="..." # A bunch of required libraries, including
# log4j-api-2.0-beta7.jar and log4j-core-2.0-beta7.jar
$ java path.to.MyClass
Welcome, please do stuff
>>>
If I use the sshfs file system mounted on my machine:
$ cd /mount-point/to/remote-machine
$ cd path/to/eclipse-project
$ export CLASSPATH="..."
$ java path.to.MyClass
<nothing happens>
I did, through Eclipse debugging, determine that LogManager#getLogger is the culprit. In fact, going a little deeper, I saw that there is a loop that starts with index=2 and only terminates when class==null, in ClassLoaderContextSelector.java:86.
来源:https://stackoverflow.com/questions/17838807/log4j-logmanager-getlogger-gets-stuck-in-an-infinite-loop