How to Handle Concurrentmodificationexception in Java

Why this problem is coming?
Concurrentmodificationexception   is may thrown by methods I mean one thread to modify a collection while another thread is iterating over it.
For example if you adding some elements to collections at the same time some other thread is removing some elements from the collections means it might throw   Concurrentmodificationexception.
How to solve it?
There are two ways available for this problem.
1.       Using synchronized method(need to consider performance issue).
2.       Using below classes.
ConcurrentHashMap
CopyOnWriteArrayList
About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 www.techpages.org · All Rights Reserved · Powered by WordPress ·