xinitrc86 / zthread

Simple Thread implementation for ABAP. Based on JAVA Thread, its Runnable interface with some additional callback capabilities.
MIT License
39 stars 8 forks source link

wait_for_free_dialog, zcl_thread #3

Closed victorizbitskiy closed 3 years ago

victorizbitskiy commented 3 years ago
    "hardcoded 3 on purpose. Less than that and systems get weird.
"   ...
    while num_free_dia_wps < 3.
      "can lead to starvation if server usage is too high for too long
      wait up to '0.2' seconds.
      call 'ThWpInfo'
      id 'OPCODE' field opcode_wp_get_info
      id 'WP' field num_wps
      id 'FREE_DIAWP' field num_free_dia_wps.
    endwhile.

Does this mean that during parallelization more than 2 users will not be able to log into the system, because will all dialog processes (DIA) be busy?

xinitrc86 commented 3 years ago

Hmmm...not exactly, this is to try and prevent that. More a failsafe, ideally is up to the client application to manage how many threads to trigger. This particular code requires at least 3 to be idle for a new thread to start, so the system is happy to take new requests from others, while the application trying to thread will have to wait for an user to disconnect or another thread to finish. I have not experienced issues with this so far. There is an unit test for it but maybe not stressing this enough...

What I should do is update the documentation explaining clients to manage the max threads running. I have plans of implementing a ThreadPoolExecutor to allow submits of threads but only having a predefined max running at a time upon invokeAll. https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

victorizbitskiy commented 3 years ago

What I should do is update the documentation explaining clients to manage the max threads running. I have plans of implementing a ThreadPoolExecutor to allow submits of threads but only having a predefined max running at a time upon invokeAll.

Yes, this is probably what needs to be done. If you are interested, you can see how I implemented this in my project.

https://github.com/victorizbitskiy/zconcurrency_api

xinitrc86 commented 3 years ago

Very nice, thank you! I see you are using SPTA framework, I was unfamiliar with it...

xinitrc86 commented 3 years ago

Implemented zcl_executors, zcl_thread_pool_executor ;)