You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the program queries the database to get all stocks, changes their prices, and then saves them for every single cycle. This could be improved by creating a system where stocks are queried at the beginning of the day and kept in memory, changing prices each cycle and then being saved at the end of the day (at which point the Map is flushed). This could be done by using a ConcurrentHashMap, ensuring that controllers and other classes will still be able to retrieve stock information while the prices are being changed. The StockManager class would control all stock-related database interactions, ensuring that stocks are not out-of-date at any point
Note: ConcurrentHashMap would create situations where stock prices are one cycle out-of-date when another class attempts to retrieve stock info during a price-change cycle. This is relatively unimportant because the price change would be insignificant. This solution would ensure thread-safety between the StockMangager and any class that uses it to retrieve stock info.
Notes:
StockManager would need a fallback mechanism, where it will get stock info directly from the database if it is not in the HashMap. This is most relevant at the end of the day, when the HashMap is saved to the database and then flushed. Between the end-of-day and the query to fill the HashMap at the beginning of the day, any retrieval attempts to the Map will fail, meaning the fallback is necessary. However, this is a fair tradeoff rather than always keeping the Stocks in the map, because it ensures that new stocks begin changing at the start of the NEXT day after they are added.
This approach makes the size of the stock classes far more relevant, and the nature of the current Stock entity means that it grows in size throughout the running of the program (with PriceHistory, NewsEvent, etc.).
The text was updated successfully, but these errors were encountered:
Currently, the program queries the database to get all stocks, changes their prices, and then saves them for every single cycle. This could be improved by creating a system where stocks are queried at the beginning of the day and kept in memory, changing prices each cycle and then being saved at the end of the day (at which point the Map is flushed). This could be done by using a ConcurrentHashMap, ensuring that controllers and other classes will still be able to retrieve stock information while the prices are being changed. The StockManager class would control all stock-related database interactions, ensuring that stocks are not out-of-date at any point
Note: ConcurrentHashMap would create situations where stock prices are one cycle out-of-date when another class attempts to retrieve stock info during a price-change cycle. This is relatively unimportant because the price change would be insignificant. This solution would ensure thread-safety between the StockMangager and any class that uses it to retrieve stock info.
Notes:
The text was updated successfully, but these errors were encountered: