[英]AbstractMethodError from java.util.Hashtable while calling get method
We have an Object CollectedInfo
, which contains a Hashtable
. 我们有一个对象CollectedInfo
,其中包含一个Hashtable
。 In our application, we populate this Hashtable
, and then iterate it to perform insert operations. 在我们的应用程序中,我们填充此Hashtable
,然后对其进行迭代以执行插入操作。 Different threads used simultaneously to perform this operation. 不同的线程同时用于执行此操作。
While retrieving the value from the Hashtable
, we see the AbstractMethodError
exception, showing the trace from get method of Hashtable
. 从Hashtable
检索值时,我们看到AbstractMethodError
异常,显示了Hashtable
get方法的跟踪。 As soon as this exception comes the java application crashes. 此异常一到,Java应用程序就会崩溃。
We are not able to reproduce the exception, however we can see the same behavior in our application very consistently over a period of time. 我们无法重现异常,但是在一段时间内我们可以在应用程序中非常一致地看到相同的行为。
Below is the trace : 下面是跟踪:
SYS_ERR: Exception running task: java.lang.AbstractMethodError
SYS_ERR: java.lang.AbstractMethodError
SYS_ERR: at java.util.Hashtable.get(Unknown Source)
SYS_ERR: at poll.CollectedInfo.getValuesForColumn(CollectedInfo.java:1026)
SYS_ERR: at poll.YYYMgr.saveData(YYYMgr.java:5346)
SYS_ERR: at poll.YYYMgr.saveData(YYYMgr.java:2412)
SYS_ERR: at poll.YYYMgr.saveData(YYYMgr.java:2250)
SYS_ERR: at poll.CommonPollAPI.saveData(CommonPollAPI.java:579)
SYS_ERR: at poll.XXXXData.run(XXXXData.java:76)
SYS_ERR: at management.scheduler.WorkerThread.run(WorkerThread.java:70)
We are using the JRE 1.6.0, and the OS where this issue is reproduce is Linux Red Hat Enterprise Linux Server release 5.6 Beta (Tikanga). 我们使用的是JRE 1.6.0,重现此问题的操作系统是Linux Red Hat Enterprise Linux Server 5.6 Beta(Tikanga)。
Firstly, a Hashtable
is basically a HashMap
, so... 首先, Hashtable
基本上是HashMap
,所以...
You have: 你有:
HashMap
一个HashMap
HashMap
concurrently 同时使用HashMap
多个线程 What need is a HashMap
that is coded for concurrent access. 需要的是为并发访问编码的HashMap
。
Fortunately, one exists already: ConcurrentHashMap
. 幸运的是,已经存在一个: ConcurrentHashMap
。 The only change you'll need to you code is to use the special thread-safe method putIfAbsent(K, V)
您需要对代码进行的唯一更改是使用特殊的线程安全方法putIfAbsent(K, V)
Take an Iterator class object and then try to get hash values. 以Iterator类对象,然后尝试获取哈希值。
//Declaration //宣言
Iterator itr = hashtable.keySet().iterator();
// Processing //处理
while(itr.hasNext())
{
String key = (String)itr.next();
String value = (String)hashtable.get(key);
// write your desired code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.