Reputation: 495
I am observing a strange behavior on a Linux box. The code works fine on Win 7. The offending code hangs on xmlToJavaMap.keySet(). Neither of the two log statements are logged!!! No deadlock found in heap dump.
ConcurrentHashMap<String,String> xmlToJavaMap = ApplicationContext.getBean("map");
logger.info("before for loop");
for (String key : xmlToJavaMap.keySet()) {
logger.info("key: " + key);
...
}
logger.info("map processed.");
Platform: java version "1.7.0_11" Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode) Red Hat 4.4.7
Upvotes: 1
Views: 350
Reputation: 1
I found the same case, hang at keySet()
method. actually the thread exit by NoSuchMethodError error.
solution is that just declare
ConcurrentHashMap<String,String> xmlToJavaMap = ApplicationContext.getBean("map");
to
Map<String,String> xmlToJavaMap = ApplicationContext.getBean("map");
or
make sure code and dependency jar is compiled by same jdk version.
the root reason is that "Undefined reference: .. ConcurrentHashMap.keySet()" when building in Java 8 , cause by:
in version 7 and 8, keySet()
method is not the same return , this error maybe is not in your project's log or console, but in heap. you can dump heap to find java.lang.NoSuchMethodError
related to keySet()
Upvotes: 0
Reputation: 495
Here is what was actually happening :)
xmlToJavaMap.keySet()
was actually failing with NoSuchMethod and the thread was terminating. The error stack trace was getting logged in a different log file which was causing the confusion. Once the error was addressed , everything back to normal.
Upvotes: 0
Reputation: 10725
Use jps -v to watch your java process. Then use jstack to watch your stack of threads. That could help you find the solution.
Upvotes: 1