4 ms·
Futures aren't a natural way to formulate many important concurrency problems. If I want a thread polling an external system and putting records in a work queue
by amarkov 9y ago
Futures aren't a natural way to formulate many important concurrency problems. If I want a thread polling an external system and putting records in a work queue for as long as my application is running... well, what's that a future of?
- sametmax 9y agoThat's what thread pools are for. They have a work queue you fill and workers depop it. Literally 5 lines in python and i imagine most modern languages.
- amarkov 9y agoRight, but thread pools are simple because they don't offer any sort of API for the tasks in the work queue. You're just writing arbitrary code. So rather than reasoning about an abstract execution model, you have to carefully think about every line to make sure you don't accidentally share mutable state.
- therealdrag0 9y agoIn Java with Spring you'd do something like: @Scheduled(fixedRate = 5000) public void poll() { getCrapAndPutOnConsumerQueue(); }