简体   繁体   中英

Log4j Maximum String Length OR Java String Concatenation Error?

Running on Solaris 10, I am having problems when I hit a LOG.debug statement using an Apache Log4j logger. The basic scenario is demonstrated in the following code block:

public class MyClass {
   private static final Logger LOG = Logger.getLogger(MyClass.class.getName());
   private LinkedHashMap<String, String> myMap = 
         new LinkedHashMap<String, String>();

   public static void main(String[] args) {

      // A really long String, but certainly not exceeding 2^31 - 1 characters 
      //long
      String reallyLongString = "A really, really, really...long String";
      String key = "keyToReallyLongString";

      // When this line is executed, Solaris instantly and completely logs me off 
      // of the system
      LOG.debug("Adding to myMap[" + key + "]: " + reallyLongString);
   }
}

Any thoughts?

If you have any type of process limits, you might be running into them. By doing that string concatenation, you will use at least (reallyLongString.length() + key.length()) * 2 bytes. If that is enough to push you over your limits…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM