public class ConcurrentModificationException extends RuntimeException
例如,它通常是不允许一个线程而另一个线程遍历它修改集合。在一般情况下,迭代的结果是不确定的,在这种情况下。一些迭代器实现(包括所有通用收集实现的JRE提供)可以选择如果检测行为抛出该异常。迭代器这样做被称为快速失败迭代器,因为他们不能迅速、干净,而冒着任意的,非在将来一个不确定的时间确定的行为。
注意,这个例外并不总是表明对象已由一个不同的线程的并发性。如果一个线程问题序列的方法调用,违反合同的对象,对象可能抛出该异常。例如,如果一个线程修改直接收集的则是在一个快速失败迭代器集合的迭代,迭代器将抛出此异常。
注意,快速失败行为不能得到保证的话,一般来说,不可能在不同步的并发修改的存在作出难以保证。快速失败的操作把ConcurrentModificationException
尽最大努力的基础上。因此,要写一个程序,依靠这一例外的正确性错误:concurrentmodificationexception只能用来检测错误。
Collection
,
Iterator
,
Spliterator
,
ListIterator
,
Vector
,
LinkedList
,
HashSet
,
Hashtable
,
TreeMap
,
AbstractList
,
Serialized Form
Constructor and Description |
---|
ConcurrentModificationException()
创建一个不含详细信息concurrentmodificationexception。
|
ConcurrentModificationException(String message)
创建一个指定详细信息的
ConcurrentModificationException 。
|
ConcurrentModificationException(String message, Throwable cause)
用指定的详细信息构造一个新的异常和原因。
|
ConcurrentModificationException(Throwable cause)
构建与指定的原因和
(cause==null ? null : cause.toString()) 详细信息新的异常(通常包含类和细节信息的
cause 。
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public ConcurrentModificationException()
public ConcurrentModificationException(String message)
ConcurrentModificationException
。
message
-详细信息关于这个例外。
public ConcurrentModificationException(Throwable cause)
(cause==null ? null : cause.toString())
详细信息新的异常(通常包含类和细节信息的
cause
。
cause
的原因(这是以后的
Throwable.getCause()
方法检索)。(一
null
值是允许的,并指出原因是不存在的或未知的。)
public ConcurrentModificationException(String message, Throwable cause)
值得注意的是,与cause
的详细信息不自动纳入该异常的详细信息。
message
的详细信息(这是以后的
Throwable.getMessage()
方法检索)。
cause
的原因(这是以后的
Throwable.getCause()
方法检索)。(一
null
值是允许的,并指出原因是不存在的或未知的。)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.