timeout and nosuspend blog

In a previous blog, we demonstrated how to use the CICS asynchronous API to start a child task and fetch its response using the FETCH CHILD command. In that example, FETCH CHILD waits for the child task to finish before it returns, which could take anywhere from milliseconds to minutes – and while it's waiting for the child to finish, the parent task is suspended in CICS, which means that it's subject to DTIMOUT and could even be purged before the FETCH CHILD command returns.

Using the new TIMEOUT and NOSUSPEND options on the FETCH CHILD and FETCH ANY commands, you have more control over parent-child behaviour, making it even easier to reach response time requirements with asynchronous applications.

Using TIMEOUT with FETCH commands

The TIMEOUT option allows you to specify the maximum time in milliseconds that the parent task will wait for a child task to complete. When TIMEOUT is specified with a non-zero value, the parent task will not be subject to DTIMOUT. Here's what a FETCH CHILD command looks like in a COBOL program with a 1 second timeout value:

EXEC CICS FETCH CHILD(CHLDTOKN) TIMEOUT(TIMEOUT1)
COMPSTATUS(CVDA)
RESP(W-RESP)
RESP2(W-RESP2)
END-EXEC.

Where TIMEOUT1 is defined as shown below, and can be changed dynamically in the program or by reading from a file or database to suit your environment.

01 TIMEOUT1     PIC S9(8) USAGE BINARY VALUE 1000.

If the child task finishes before TIMEOUT is reached the command will return immediately. If the child task hasn’t finished before TIMEOUT is reached, a NOTFINISHED condition will occur with a RESP2 value of 53. You can check the condition and decide the next step in your application. The same applies to the FETCH ANY command.

Using NOSUSPEND with FETCH commands

Sometimes it is acceptable for your business application to present any possible result to the end user, but an immediate response is important to them. In these cases, the NOSUSPEND option can be used to get an available result without wasting any time waiting. A FETCH command with NOSUSPEND looks like this:

EXEC CICS FETCH CHILD(CHLDTOKN) NOSUSPEND
COMPSTATUS(CVDA)
RESP(W-RESP)
RESP2(W-RESP2)
END-EXEC.

If the child task has finished when the command is issued, the command will return immediately with a NORMAL response. If the child hasn’t finished, the NOTFINISHED condition will occur with RESP2 value of 52.

Using these options in your application

You can use TIMEOUT and NOSUSPEND on your FETCH CHILD and FETCH ANY commands to improve application versatility and meet business needs in a variety of situations:

  • For any child tasks that you will definitely need a response from, use FETCH without TIMEOUT or NOSUSPEND.
  • For child tasks from which you need the response in a timely fashion, specify a TIMEOUT value on your FETCH command.
  • For child tasks where no response is acceptable, specify NOSUSPEND on your FETCH command.

Example

The following is a COBOL example, ASYNCPG1, which demonstrates the various flavours of FETCH commands. The parent program starts four child tasks, and it needs the response from the first child SUB1, so we have:

EXEC CICS FETCH CHILD(CHLDTOKN1) CHANNEL(CHLDCHNL1)
           COMPSTATUS(CVDA)
           RESP(W-RESP) RESP2(W-RESP2)
           END-EXEC.

For the second child SUB2, the parent program can wait for up to 1000 milliseconds when fetching the response, so we have:

EXEC CICS FETCH CHILD(CHLDTOKN2) CHANNEL(CHLDCHNL2)
           TIMEOUT(TIMEOUT1)
           COMPSTATUS(CVDA)
           RESP(W-RESP) RESP2(W-RESP2)
           END-EXEC.

For the third and fourth children, SUB3 and SUB4, the parent program can have any result, but can't afford to wait, so we have:

EXEC CICS FETCH ANY(ANYTOKN) CHANNEL(ANYCHNL)
           NOSUSPEND COMPSTATUS(CVDA)
           RESP(W-RESP) RESP2(W-RESP2)
           END-EXEC.

The complete source code from which these snippets were taken is available on GitHub. Go to the IBM Knowledge Center for more detailed information about TIMEOUT and NOSUSPEND on FETCH CHILD and FETCH ANY.

3 comments on"Improving response times with TIMEOUT and NOSUSPEND in asynchronous applications"

  1. Cesar Altamirano September 22, 2017

    For child tasks that you will definitely need a response from, use FETCH without TIMEOUT or NOSUSPEND.
    For child tasks from which you need the response in a timely fashion, specify a TIMEOUT value on your FETCH command.
    For child tasks where no response is acceptable, specify NOSUSPEND on your FETCH command.

    Should say:
    For Any child tasks that you will definitely need a response from, use FETCH without TIMEOUT or NOSUSPEND.
    For child tasks from which you need the response in a timely fashion, specify a TIMEOUT value on your FETCH command.
    For child tasks where no response is acceptable, specify NOSUSPEND on your FETCH command.

  2. Cesar Altamirano September 22, 2017

    For child tasks that you will definitely need a response from, use FETCH without TIMEOUT or NOSUSPEND.

    Should say:
    For Any child tasks that you will definitely need a response from, use FETCH without TIMEOUT or NOSUSPEND.

Join The Discussion

Your email address will not be published. Required fields are marked *