Concurrency in custom rest service

10 views
Skip to first unread message

Christoph Damm

unread,
Oct 8, 2024, 2:24:20 AM10/8/24
to Magnolia User Mailing List
Hello,
i have a general question.
I have the situation that i have some custom rest endpoints which do some heavier data fetching, sometimes for several items of a workspace (And their related workspaces).
Now i want to parallelize theis fetching.
E.g. i have a list of products and need to enhance those with various data from other workspaces.
I want to simply iterate over this list of products in parallel.
Now:
Within the method of MgnlContext is used, which is thread local as well as some webrequest data (mainly to compose urls in a multisite setup). By nature those are not available in a separate thread.
What's the "normal" way to do so?
I tried with copying the mgnlcontext or use the doInSystemContext (Doesn't sound right and doesn't have the webcontext) but this lead to weird unclosed session behaviour.+

Thank you and regards,

Chris

Roman Kovařík

unread,
Oct 8, 2024, 2:36:56 AM10/8/24
to Magnolia User Mailing List, christo...@gmail.com

Hi Chris,

Do you use the second parameter of doInSystemContext to close the sessions?
The WebContext isn’t available, as it’s bound to the request thread, so any request information should be retrieved before spawning the threads. 🤞

Hope that helps,
Roman

Christoph Damm

unread,
Oct 8, 2024, 2:50:27 AM10/8/24
to Roman Kovařík, Magnolia User Mailing List
Hi Roman,

I'm not entirely sure, i thought i tried that as well, but can do again.
Hm with the webcontext: yes, however i will have to check how I can do this nicely without cluttering my code as i do not want to pass the needed info to each and every mapper.
Could maybe also map information that needs webrequest info separately, but I'll have to dig deeper into that.
Will report back once checked.

Regards,
Christoph
Reply all
Reply to author
Forward
0 new messages