2

I am trying to implement thread safe ArrayList Collection,

I want my collection should put lock at an item level instead of on complete collection.

Let say if my collection has 10 items, so 10 threads can update value simultaneously from index 1 to 10, Since they are update different array item , so it should be allowed. Here update doesn't include removing an item from ArrayList

I don't want use in built concurrent collections, because of addition overhead.

Is there any locking mechanism available to put lock on individual item of ArrayList.

Thanks

2
  • 6
    "I don't want use in built concurrent collections, because of addition overhead." => most probably, your own custom implementation based on lock will have a greater overhead... Commented Sep 10, 2015 at 12:35
  • Really: What @ken2k said. Commented Sep 10, 2015 at 12:43

1 Answer 1

1

Try to use ReadOnly Collection Or ArrayList.IsSynchronized or ArrayList.Synchronized

Sign up to request clarification or add additional context in comments.

1 Comment

Synchronized ArrayList also put a lock on complete collection level, basically it just add extra locking step to every add, remove and other methods of collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.