I am working on a larger website, and i would like to make "long running" parts of the program run on separated thread. But I am kind of torn on how to make this happen, and though I would ask if anyone have solved a similar issue. The reason I would like to this is because among other things I send emails to users and there a quite a few database lookups before the email is send, it would not be necessary to lock the user while all this happens. There are also other cases where I would like to wait some time to send the email, in case more emails are to be sending, and then combine them.
I have thought of 2 ways to do this:
- Have a thread running that is started in application state, that then will run the backend processing. This will enable me to send objects directly to the thread.
- Have a program running on the side, and send data to it via a table in my database.