简体   繁体   English

Java ConcurrentHashMap.keySet()挂起

[英]Java ConcurrentHashMap.keySet() hangs

I am observing a strange behavior on a Linux box. 我在Linux机器上观察到奇怪的行为。 The code works fine on Win 7. The offending code hangs on xmlToJavaMap.keySet(). 该代码在Win 7上运行良好。有问题的代码挂在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 平台:Java版本“ 1.7.0_11” Java™SE运行时环境(内部版本1.7.0_11-b21)Java HotSpot(TM)64位服务器VM(内部版本23.6-b04,混合模式)Red Hat 4.4.7

Use jps -v to watch your java process. 使用jps -v监视您的Java进程。 Then use jstack to watch your stack of threads. 然后使用jstack观察线程堆栈。 That could help you find the solution. 那可以帮助您找到解决方案。

Here is what was actually happening :) xmlToJavaMap.keySet() was actually failing with NoSuchMethod and the thread was terminating. 这是实际发生的事情:) xmlToJavaMap.keySet()实际上由于NoSuchMethod失败,线程正在终止。 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. 解决错误后,一切恢复正常。

I found the same case, hang at keySet() method. 我发现相同的情况,挂在keySet()方法上。 actually the thread exit by NoSuchMethodError error. 实际上,该线程由于NoSuchMethodError错误而退出。 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. 确保代码和依赖项jar由相同的jdk版本编译。

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. 根本原因是在Java 8中进行构建时“未定义引用:.. ConcurrentHashMap.keySet()”的原因是:在版本7和8中, keySet()方法返回的结果不同,此错误可能不在您的项目中日志或控制台,但在堆中。 you can dump heap to find java.lang.NoSuchMethodError related to keySet() 您可以转储堆以查找与keySet()相关的java.lang.NoSuchMethodError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Java 8 中构建时的“未定义引用:.. ConcurrentHashMap.keySet()” - “Undefined reference: .. ConcurrentHashMap.keySet()” when building in Java 8 ConcurrentHashMap.keySet()。removeAll()性能问题 - ConcurrentHashMap.keySet().removeAll() performance issue ConcurrentHashMap.keySet().stream() 的一致性行为 - Consistency behaviour of ConcurrentHashMap.keySet().stream() ProcessSimulator.killAllProcesses(line:78)NoSuchMethodError ConcurrentHashMap.keySet() - ProcessSimulator.killAllProcesses(line:78) NoSuchMethodError ConcurrentHashMap.keySet() Java错误java.util.concurrent.ConcurrentHashMap.keySet - Java error java.util.concurrent.ConcurrentHashMap.keySet 如何在Java中创建不区分大小写的键集ConcurrentHashMap? - How can I make a case insensitive keyset ConcurrentHashMap in java? Tomcat 7 NoSuchMethodError:java.util.concurrent.ConcurrentHashMap.keySet() - Tomcat 7 NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet() ConcurrentHashMap的KeySet迭代器是线程安全的吗? - Is KeySet iterator of ConcurrentHashMap is threadsafe? ConcurrentHashMap中的keySet(V mappingValue)到底如何工作? - How exactly keySet(V mappedValue) in ConcurrentHashMap works? concurrenthashmap java - concurrenthashmap java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM