bisq-network / bisq-pricenode

GNU General Public License v3.0
6 stars 12 forks source link

PriceProvider: Add volatile to cachedResult field #43

Closed alvasw closed 10 months ago

alvasw commented 11 months ago

The get() and put() calls can happen on different threads. The volatile keyword makes sure that all updates to cachedResult are visible to all threads.

Relates to #33.

alvasw commented 11 months ago

Every ExchangeRateProvider starts its own Timer running on its own background thread. When many clients call the REST API at the same time, several threads from the server thread pool handle the requests concurrently. Without the volatile keyword these threads could return a stale state because the last updates are not visible to them yet.

Timer / Background Thread Creation: https://github.com/bisq-network/bisq-pricenode/blob/6073a3948e7567359adf9f167c27d65a7e352d9a/src/main/java/bisq/price/PriceProvider.java#L69-L81

ghost commented 11 months ago

ACK