I have a series of tasks that have to be executed at certain points in time (long time in the future, days and possibly weeks). My plan was to create for each a thread that waits until its time is due. Since the number of tasks can be quite hi, I am concerned that those threads combined will consume a lot of resources (to do nothing/ to wait). My question is if a thread that waits consumes resources and if yes how many.
(I asume that creating a database of tasks and constantly iterating through it to see if any should be executed is even less efficient)
This is not really a scala-specific issue.
The problem with having a thread wait for a long period of time is that your application might crash in the meantime or you might have a power outage or whatever.
Storing it in the database sounds like a straightforward solution to me on the other hand. Sure it would be quite time-consuming if you iterated through all entries all the time. However if you have "due" field in the database, based on which you can sort, this should be fairly efficient. Obviously you'd need to choose an appropriate database that efficiently supports such operations, but in effect, this will allow you to build a more reliable system that may continue to work correctly after the application was restarted.