• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[red]If two process in application updating one java.util.List object then which kind of exception will be raised?[/red]

help me please.
 
Greenhorn
Posts: 16
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
shyam sunder prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks rajashekar,
 
shyam sunder prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankyou Greenhorn
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic