Ethan Solomon
Ethan Solomon

Reputation: 353

Is using a reentrant read write lock the fastest approach?

For a stock market algorithm, I am implementing an observable pattern for handling quotes. The "observers" are a list of triggers. The issue, is that this list can change (add a trigger, remove a trigger, etc), so I have to deal with concurrent modification errors.

I for sure do not want to use synchronize on the list or a copyOnWriteArrayList, as that is way too slow. The handling of quotes needs to be async. I only want to lock the list if the list changes. I'm thinking about using a ReentrantReadWriteLock. When the list needs to change, acquire the write lock. If handling a quote, use a read lock. Is this the best approach to dealing with this? My goal is completely async handling of quotes, but to lock the list if I need to modify it

Upvotes: 0

Views: 40

Answers (0)

Related Questions