Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

PB & multithreading & loops = not responding

I am using PB12.5

I created a pbl that has a window and it creates 10 threads each of which connects to the database and starts a timer which sends a simple select to the database.  It creates traffic over the network.

I can see the traffic when I go to resmon (windows resource monitor) and go to overview tab and click on PB125.exe

then go to the network tab and under TCP connections I right click on title and make sure I can see: send receive total

I will see each of the 10 threads and the traffic it is sending.

What doesn't work is when I have a long loop in the application.  (click on LOOP button) Then the threads stop sending data.

On the Resource Monitor it will dwindle down to 0 traffic.  Which means the threads are not running

When I put a yield in the loop it works but it is slow and it is multithreaded then I shouldn't have to do that.

Maybe I didn't set it up correctly -  I attached the pbl.

I can send the pbl.  i

Window creates NVO (main) which adds an array of 10 NVOs (TR) with transaction objects.

Each NVO (TR) creates a thread which sends out network traffic every N seconds.

In the Window there is a LOOP button and when that is click it just goes into a loop (doesn't do anything)

pbl 8 objects

muti: application object opens window

w_multi: window has open event which creates the NVO (main) and executes a function which adds 10 connections

n_trnvo_main: NVO main has one fx that creates 10 NVO transactions

n_trnvo NVO transactions connects to the database and creates a thread passing itself to the subthread

nv_shared: shared NVO creates a timer which call ue_wakeup every 5 secs
n_timer: calls ue_wakeup in nv_shared

nv_arg: executes SQL

n_tr: transaction object

ue_wakeup event executes subthread ue_wakeup event which executes the NVO transaction to send SQL

the code is here:

Click the ORANGE download button the other buttons are advertisements

I really appreciate any help.  This has me stumped.  TIA

Former Member replied

That's usually the MT application's downfall when you code processing logic like that in the main thread. All the main thread should do is sleep, wake up, pole the sub-thread's for completed work, assign new work and then go back to sleep (nothing else).

For the DW processing, that should all be encapsulated in a sub-thread within a DS. When the sub-thread  completes, it can either post the main thread or wait to be polled for a completion status. Once the sub-thread has the DS result set loaded, the main thread can just do a ShareData() to populate the DC.

I would also encourage the DS processing thread to connect asynchronously and still issue a Yield() if a liopy is required to process the DS buffers after the Retrieve().

FWIW: Also, instantiate your transaction objects in the NVUO sub-thread as an instance variable. I would not share any work areas with the main thread and never use any global variables in the sub-threads.


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question