在Java API里已经解释了这个ConcurrentModificationException异常的来历:
当方法检测到对象的并发修改,但不允许这种修改时,抛出此异常。
例如,某个线程在 Collection 上进行迭代时,通常不允许另一个线程修改该 Collection。通常在这些情况下,迭代的结果是不明确的。如果检测到这种行为,一些迭代器实现(包括 JRE 提供的所有通用 collection 实现)可能选择抛出此异常。执行该操作的迭代器称为快速失败 迭代器,因为迭代器很快就完全失败,而不会冒着在将来某个时间任意发生不确定行为的风险。
注意,此异常不会始终指出对象已经由不同 线程并发修改。如果单线程发出违反对象协定的方法调用序列,则该对象可能抛出此异常。例如,如果线程使用快速失败迭代器在 collection 上迭代时直接修改该 collection,则迭代器将抛出此异常。
注意,迭代器的fail-fast快速失败行为无法得到保证,因为一般来说,不可能对是否出现不同步并发修改做出任何硬性保证。快速失败操作会尽最大努力抛出 ConcurrentModificationException。因此,为提高此类操作的正确性而编写一个依赖于此异常的程序是错误的做法,正确做法是:ConcurrentModificationException 应该仅用于检测 bug。
Iterator 是工作在一个独立的线程中,并且拥有一个 mutex 锁。 Iterator 被创建之后会建立一个指向原来对象的单链索引表,当原来的对象数量发生变化时,这个索引表的内容不会同步改变,所以当索引指针往后移动的时候就找不到要迭 代的对象,所以按照 fail-fast 原则 Iterator 会马上抛出 java.util.ConcurrentModificationException 异常。
所以 Iterator 在工作的时候是不允许被迭代的对象被改变的。但你可以使用 Iterator 本身的方法 remove() 来删除对象, Iterator.remove() 方法会在删除当前迭代对象的同时维护索引的一致性。
有意思的是如果你的 Collection / Map 对象实际只有一个元素的时候, ConcurrentModificationException 异常并不会被抛出。这也就是为什么在 javadoc 里面指出: it would be wrong to write a program that depended on this exception for its correctness: ConcurrentModificationException should be used only to detect bugs.
下面的代码没有问题:
- import java.util.*;
- public class TryIteratorRemove {
- public static void main(String [] args){
- Collection<String> myCollection = new ArrayList<String>(10);
- myCollection.add("123");
- myCollection.add("456");
- myCollection.add("789");
- int i=0;
- for(Iterator it = myCollection.iterator();it.hasNext();) {
- String myObject = (String)it.next();
- System.out.println(myObject);
- i++;
- if(i==1){
- //myCollection.remove(myObject); //这行代码有问题,会抛出ConcurrentModificationException
- it.remove();
- }
- }
- System.out.println("After remove,the size of myCollection is: " +
- myCollection.size()+" \n and its content is: ");
- for(String s : myCollection){
- System.out.println(s);
- }
- }
- }
虽然在Quartz上有配置Quartz集群Clustering ,但是在Spring中使用Quartz任务调度并支持集群系统却有些问题,下面介绍解决办法:
- FORMATTING DECIMAL NUMBERS
- 格式化数字,科学计数法
- Internet Explorer - User-Agent test and override registry scripts
- 存储空间不足 无法完成此操作:
- reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform" /f
- reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform" /f
- reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform" /f
- reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform" /f
- Open Source Native XML Database
- The 7 Stages of Scaling Web Apps | High Scalability
- 【原】Java Reflection 之 Method - pengpenglin - BlogJava
- Java反射 Reflection
- IBM WebSphere Developer Technical Journal: The top Java EE best practices
- IBM WebSphere Developer Technical Journal: The top 10 (more or less) J2EE best practices
- Top 10 Concepts That Every Software Engineer Should Know - ReadWriteWeb
- 南方网-广州市人口准入基本条件(二)
- 南方网-广州市人口准入基本条件(一)
- 1 Minute HOWTO Guides
- ubuntu,fedora,centos,freebsd如何升级安装软件包,设置操作系统语言
- Clean up your Web pages with HTML TIDY
- weeker.org » Blog Archive » Ubuntu 源列表
- squid3.0反向代理 apache+squid_蒜头网
- lighttpd+tomcat+squid3.0_蒜头网
- 高并发高流量网站架构 - 技术门户 | ITPUB |
- 使用 Nginx 提升网站访问速度
- Nginx是一个web 服务器
- Java performance tuning tips
- Java性能调优
- Ana's Lair: crt1.o: No such file: No such file or directory
- 解决下面的问题: C compiler cannot create executables /usr/bin/ld: crt1.o: No such file: No such file or directory
- Linux下./configure错误详解-王琬的BLOG-搜狐博客
- 解决下面的问题: C compiler cannot create executables /usr/bin/ld: crt1.o: No such file: No such file or directory
- 每个项目最重要的十件事 - 软件 - JavaEye新闻
- MG4J: Managing Gigabytes for Java™
- lucene的第二选择,一个搜索引擎
- memcached-tool
- memcached monitor 监视
- 十个最好的Java性能故障排除工具 - Java - JavaEye新闻
- 敏捷质疑: 持续集成 - 切尔斯基 - BlogJava
- SpringSource Team Blog » Dynamic DataSource Routing
- Spring+Hibernate多数据源解决方案
- Horizontal Database Partitioning with Spring and Hibernate - ... - JavaEye技术网站
- Spring+Hibernate框架下,多数据源Datasource,多sessionFactory的水平数据库分区分割解决方案
- spring之多SessionFactory - Spring - Java - JavaEye论坛
- Spring+Hibernate框架下,多数据源Datasource,多sessionFactory的水平数据库分区分割解决方案
- Oracle10g学习笔记 | 专注.NET 、JAVA技术
- yanfs: yanfs
- 文件系统,远程访问驱动器
- 站长日志 - 面向网站站长的专业网络开发、网站运营博客
- css 参考
质检总局建议停止食用以前购买的无法确定是否含三聚氰胺的奶粉
2008年9月21日,质检总局官方网站发布的关于乳制品安全相关问题答复新闻中,第三点《关于查询消费者已购买的婴儿配方奶粉是否合格的问题》指出
“打消家长顾虑的最好办法,是停止食用以前购买的奶粉,孩子的健康毕竟比几袋奶粉贵重多了”。
Tapestry5必须有一个"module builder class",很典型地,经常是叫"AppModule",AppModule经常用来定义一些新服务、覆盖原始服务、或者为服务更改配置。常用的是让Tapestry5支持UTF-8的request Encoding、忽略一些路径过滤来支持Servlet和其他Servlet Filter的开发等。下面的代码可以加在AppModule中:
Tapestry5通过在web.xml下定义tapestry.app-package指向的Java包里寻找AppModule,也就是<filter-name>加上"Module"字符。
下面是官方文档里Tapsetry IoC 配置:
Tapestry IoC Configuration
Most other configuration occurs inside your application's module builder class. The application module builder will often define new services, provide overrides of services, or make contributions to service configurations.
Tapestry looks for a module builder class in the services package (under the root package). It capitalizes the <filter-name> and appends "Module". In the previous example, the module builder class would be org.example.myapp.services.AppModule.
If such a class exists, it is added to the IoC Registry. It is not an error for your application to not have a module, though any non-trivial application will have a module.
- Settingup an FTP Server on Ubuntu with ProFTPD -- Ubuntu Geek
- Setting Up a Telnet Server in Ubuntu -- Ubuntu Geek
- IBM WebSphere 开发者技术期刊: 使用 J2EE Connector Architecture 进行 WebSphere Application Server 和 CICS 的事务集成
- 使用 JFreeChart来创建基于web的图表
- IBM WebSphere Developer Technical Journal: Transactional high availability and deployment considerations in WebSphere Application Server V6
- 在tapestry的html里的head标签里增加meta等html内容
- Qref/Hardy - Ubuntu中文
- 零命令玩转Ubuntu 8.04 之 配置篇 (系统微调) | iLoveMac.cn
- Does a similar app also exist for Macs or Linux? | TortoiseSVN
- Ubuntu中文 论坛 :: 阅读主题 - 中文输入法
- ubuntu 8.04中文环境解决方法 - 开发者在线 - www.builder.com.cn
- 来个Ubuntu 8.04的更新源
“专业软件工程师”,是指具有规范化的价值观和知识体系,规范化的工作习惯和职业纪律,职业化的工作作风和流程,当然也具有相应的技能和经验。