In a thread-safe ESQL/C application, the DORMANT option makes an active connection dormant. Another thread can now use the connection by issuing the SET CONNECTION statement without the DORMANT option. A thread-safe environment can have many threads (concurrent pieces of work performing particular tasks) in one ESQL/C application, and each thread can have one active connection.
An active connection is associated with a particular thread. Two threads cannot share the same active connection. Once a thread makes an active connection dormant, that connection is available to other threads. A dormant connection is still established but is not currently associated with any thread. For example, if the connection named con1 is active in the thread named thread_1, the thread named thread_2 cannot make connection con1 its active connection until thread_1 has made connection con1 dormant.
The following code fragment from a thread-safe ESQL/C program shows how a particular thread within a thread-safe application makes a connection active, performs work on a table through this connection, and then makes the connection dormant so that other threads can use the connection:
thread_2() { /* Make con2 an active connection */ EXEC SQL connect to 'db2' as 'con2'; /*Do insert on table t2 in db2*/ EXEC SQL insert into table t2 values(10); /* make con2 available to other threads */ EXEC SQL set connection 'con2' dormant; }
If a connection to a database environment was initiated using the CONNECT . . . WITH CONCURRENT TRANSACTION statement, any thread that subsequently connects to that database environment can use an ongoing transaction. In addition, if an open cursor is associated with such a connection, the cursor remains open when the connection is made dormant.
Threads within a thread-safe ESQL/C application can use the same cursor by making the associated connection current, even though only one thread can use the connection at any given time.
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]