Problem:
This demonstration works fine on Net Express and on Server Express.
The aim of this demonstration is to simulate a functionality which exists on the transation manager TDS of GCOS7
which launches x transactions ( == PROCESSES ) launching x TPRs ( == x COBOL programs )
under TDS, when a transaction has overpassed a TimeLimit, TDS stops the transaction....
Resolution:
The multithreaded launcher named ctrlbythread
gets the command-line
retrives the firts parameter of the command line ( which is the program to be called )
sets a new command-line with the parameters after the firts one == program to be called
( see KB 21920: http://supportline.microfocus.com/mf_kb_display.asp?kbnumber=21920)
sets an error handler and an exit handler
controls when the program is runned in multi-threaded environment
creates a thread which aim is to control how long the process has been running
creates another thread which aim is to launch the existing application ( legacy code ... )
suspends itself..... (CBL_THREAD_SUSPEND )
it will be awaked (CBL_THREAD_RESUMLE )
or by the The 'Control'' Thread or by The 'application' Thread
depending on the 'TimeLimit' was reached or not...
The 'Control'' Thread
=============
LOOP
sleeps for a delay
gets awake
checks when the 'TimeLimit' is reached
IF YES .... it kills the 'application thread'
awakes (CBL_THREAD_RESUMLE ) the main thread
IF NO ..... sleeps again == beginning of the LOOP
END-LOOP
The 'application' Thread
==============
just calls the 'program to be called' ( firts parameter of the initial command-line)
kills the 'Control'' Thread when it has terminated...
awakes (CBL_THREAD_RESUMLE ) the main thread
The demonstration attached contains different files:
===============================
CLctrlbythread.bat :
Compilation&Link under Net Express command-line
LAUNCHctrlbythread.bat
:
launch ctrlbythread under NetExpress
( ctrlbythread legacycode 1 2 3 4 5 6 7 8 9 10)
CLctrlbythread.sh
:
Compilation&Link unde Server Express
LAUNCHctrlbythread.sh
:
launch ctrlbythread underServer Express
CtrlByThread.cbl
:
multithreaded launcher
COMLIN3.cbl :
legacycode
== existing application not modified
legacycode.cbl :
legacycode
== existing application not modified
Trace of the execution of the demonstration:
===========================
ctrlbythread legacycode 1 2 3 4 5 6 7 8 9 10 !!!!!! command launched
*-> OK running in Multithreaded RTS
*-> Entry EXITERROR found OK
*-> CBL_ERROR_PROC 0000000000 OK !!!!!!! Set error handler
*-> CBL_EXIT_PROC 0000000000 OK !!!!!!! Set exit handler
*-> CblCreateThreadCTRL begins !!!!!!! create The 'Control'' Thread
*-> CBL_THREAD_CREATE 0000000000 OK !!!!!!! create The 'Control'' Thread
*-> CblCreateThreadCTRL ends !!!!!!! create The 'Control'' Thread
*-> CblCreateThreadAPPLI begins !!!!!!! create The 'application'' Thread
*-> CBL_THREAD_CREATE !!!!!!! create The 'application'' Thread
*-> CblCreateThreadAPPLI ends !!!!!!! create The 'application'' Thread
....
*-> Main thread waits THREADAPPLI !!!!!!!! main thread waiting to be RESUMEd
!!!!!!!! legacycode runned in application thread
*-> LegacyCode Number of params received: 0000000010
*-> LegacyCode Parameter 01 Value: 1
*-> LegacyCode Parameter 02 Value: 2
*-> LegacyCode Parameter 03 Value: 3
*-> LegacyCode Parameter 04 Value: 4
*-> LegacyCode Parameter 05 Value: 5
*-> LegacyCode Parameter 06 Value: 6
*-> LegacyCode Parameter 07 Value: 7
*-> LegacyCode Parameter 08 Value: 8
*-> LegacyCode Parameter 09 Value: 9
*-> LegacyCode Parameter 10 Value: 10
*-> LegacyCode 000000000000100000
*-> LegacyCode 000000000000200000
*-> LegacyCode 000000000000300000
*-> LegacyCode 000000000000400000
*-> LegacyCode 000000000000500000
*-> LegacyCode 000000000000600000 !!!!!!!! legacycode runned in application thread
*-> THREADCTRL awake: !!!!!!!! 'control thread' awake and sleep again
LegacyCode 000000000000700000 !!!!!!!! legacycode runned in application thread
*-> LegacyCode 000000000000800000
*-> LegacyCode 000000000000900000
*-> LegacyCode 000000000001000000
*-> LegacyCode 000000000001100000
*-> LegacyCode 000000000001200000
*-> LegacyCode 000000000001300000 !!!!!!!! legacycode runned in application thread
....
....
*-> THREADCTRL awake: !!!!!!!! 'control thread' awake
*-> THREADCTRL Kill THREADAPPLI !!!!!!!!! 'TimeLimit' reached... Kill 'application' thread
*-> THREADCTRL CBL_THREAD_KILL 0000000000 OK
*-> THREADCTRL CBL_THREAD_RESUME 0000000000 OK !!! CBL-THREAD-RESUME main thread
...
*-> Main thread awake !!!!!!!!!! main thread 'awake'
*-> OK MAxElapsedTime !!!!!!!!!! information on the reason of the end of the process
*-> entry: EXITERROR EXIT-handler OK !!!!!!! exit handler called
*-> CBL_GET_EXIT_INFO:0000000000/0000000000/