This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes if two procesess updating a Collection at a time then which exception will raise Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "if two procesess updating a Collection at a time then which exception will raise" Watch "if two procesess updating a Collection at a time then which exception will raise" New topic
Author

if two procesess updating a Collection at a time then which exception will raise

shyam sunder prasad
Ranch Hand

Joined: Mar 23, 2011
Posts: 62
[red]If two process in application updating one java.util.List object then which kind of exception will be raised?[/red]

help me please.
Rajasekar Krishnan
Greenhorn

Joined: Feb 27, 2008
Posts: 16

Hi Shyam,

ArrayList is not ThreadSafe.

When two threads are accessing same list, alteast the list accessing part need to be synchronized.

Otherwise for example, one thread might remve a object from the list, in the mean time another thread tries to get the same object from the list, in this cases you may get the Exception IndexOutOfBoundsException.

Thanks,
Rajasekar.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

How about you try it?

A number of exceptions can be thrown, depending on the collection and the way the updates overlap. Without proper synchronization an ArrayList's internal structure can become corrupted, and then any RuntimeException can be thrown. ArrayIndexOutOfBoundsException is probably the most common.

Of course, even with synchronization, ConcurrentModificationException is always a possibility when iterating and modifying at the same time. You can even do that using one single process:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shyam sunder prasad
Ranch Hand

Joined: Mar 23, 2011
Posts: 62
thanks rajashekar,
shyam sunder prasad
Ranch Hand

Joined: Mar 23, 2011
Posts: 62
thankyou Greenhorn
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if two procesess updating a Collection at a time then which exception will raise
 
Similar Threads
Two bucket puzzle
one column is not getting updated in INSERT
Maven 1.0.2 Report Generation.
swing component exception
what is the problem with this code?