Pergunta

I have a hazelcast instance adding objects to a list and other nodes removing and adding objects to that list. i dont have any synchronization in place in code.

just

private static List> ordered = h.getList("my-distributed-list");

and nodes adding/removing Job s from the lists in ordered.

Should i be worried about synchronization across nodes on multiple machines ? say 100 nodes or more..

Foi útil?

Solução

There are a few things you need to be careful with:

The list itself is threadsafe, you can't corrupt it with concurrent access.

But.. if your logic is not threadsafe, then the list is not going to help you, e.g.

int indexOf = list.indexOf("foo");
if(index!=-1) {
    list.remove(indexOf)
}

Then this contains a race problem because the read of the index and the removal of the item with the given index, is not an atomic operation.

Apart from have race problems in your own logic, too much contending threads can cause performance/scalability problems since a list isn't a particularly modify friendly data-structure.

So a list can be your friend if you know what you are doing.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top