

IFuture allows you to establish a priority for the running code blocks and still return the results when needed.
#Parallel processing free#
I used this when I’d written a BW extractor, and the person who set up the process chains to run the extractor was running it like twenty times in parallel, with each of those requesting 20 slots.Īs a result, although initially there were enough free processes, they rapidly ran out. This will cause a wait loop until there are enough resources again. The task for writing ABAP Unit Tests is left to the reader!Īfter the CALL FUNCTION, you can use the handle_resource_failure method.

Me->clear_thread( CONV char8( p_task ) ). " Free the thread for the next thread to run ĮXCEPTIONS communication_failure = 1 MESSAGE errmsg

DATA(thread) = me->handler->get_free_thread( ).ĬALL FUNCTION 'Z_.' STARTING NEW TASK threadĭESTINATION IN GROUP zcl_thread_handler=>c_default_groupįinally, in method on_end_of_action (which has a single importing parameter p_task type clike) in your main application, you receive the results. In your do_stuff_in_parallel method, you have the call to the function module that does the work. The first statement after the ENDLOOP should be WAIT UNTIL me->handler->all_threads_are_finished( ). Start your loop that contains the call to the logic that you want to run in parallel. (The code automatically limits it to no more than half of the available thread on the appserver). To use it, instantiate with a prefix to use for the task id, and the ideal number of threads you want to run in parallel. READ TABLE me->threads_list WITH KEY used = abap_false ASSIGNING field-symbol(). WAIT UNTIL me->used_threads LT me->threads. IF free_threads LE 1 AND me->threads GT 1. INSERT VALUE #( thread = me->task_prefix & threadn used = abap_false ) " Ensure that no more than half of the free threads are used READ TABLE me->threads_list WITH KEY used = abap_true thread = i_taskĭATA(free_threads) = me->get_free_threads( ). MESSAGE ID sy-msgid TYPE 'X' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. " Something has gone seriously wrong, so end it here. " Already initialised - get current number of free threadsĬALL FUNCTION 'SPBT_GET_CURR_RESOURCE_INFO' Threads_list TYPE TABLE OF ty_thread WITH DEFAULT KEY, !i_group TYPE rzlli_apcl DEFAULT c_default_group, Inspired by this blog, Bruno Esperança, I though I would share a useful, reusable class I developed for making parallel processing simple, by abstracting away and encapsulating all the technical stuff.Ĭ_default_group TYPE rzlli_apcl VALUE 'parallel_generators', "#EC NOTEXTĬ_task TYPE char6 VALUE 'PARALL'.
