Sync. List or Unmodifiable List - better way.

L

Laax

Hi,

I am using a list with external sync.

What if I use the list for updation and use unmodifiable list for
iterators by different thread?

What is costly? What happens internally?
Your help is greatly appreciated.
Thanks.
 
J

John C. Bollinger

Laax said:
Hi,

I am using a list with external sync.

What if I use the list for updation and use unmodifiable list for
iterators by different thread?

What is costly? What happens internally?
Your help is greatly appreciated.
Thanks.

Collections.unmodifiableList(List) "returns an unmodifiable view of the
specified list." (API docs). In other words, the object returned by
that method has dynamic dependency on the original List. This means,
among other things, that an unmodifiable List does not provide any
measure of thread safety vs. concurrent modification of the original List.

Note also that if the List(s) contain mutable objects then thread safety
furthermore depends on correct synchronization of access to them.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top