Jump to content
ertank

How to access database for doing additional task in a separate thread in MARS

Recommended Posts

Hello,

 

There are some chain requests triggered from clients. Some requests among them takes time processing on the server side. I should send a response to client fast. Server side operations are not relevant to the response.

 

Since, MARS is handling each request in a separate thread, I also created a custom thread for this time consuming operation and process it. My problem is, database context is removed as soon as response is sent and its thread is destroyed. Any further database operations from that point in my custom thread results in access violation.

 

Is there a way that I can get a database connection from MARS database pool for my own custom threads independent of requests?

 

Thanks & Regards,

Ertan

Share this post


Link to post

Don't mess with the threads or DB connections of the HTTP/REST server. You would depend on an implementation detail of Mars, with no guaranty it stays the same in the future.

If you have a long process, then a temporary dedicated connection is just fine.

You could reuse the thread and its connection, for the next requests: add a queue to your thread, for pending requests.

Edited by Arnaud Bouchez

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×