ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahw_5.4.0.1/rzahwdbcco.htm

161 lines
10 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Database considerations for multithreaded programming" />
<meta name="abstract" content="You should consider these items when using databases in multithreaded programs." />
<meta name="description" content="You should consider these items when using databases in multithreaded programs." />
<meta name="DC.Relation" scheme="URI" content="rzahwas4co.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahwrzahwe22e22rx.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahwdioco.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahwrzahwe22e22rx.htm" />
<meta name="DC.Relation" scheme="URI" content="../rbam6/rbam6clmain.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstthreads.htm" />
<meta name="DC.Relation" scheme="URI" content="../cli/rzadpkickoff.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahwexico.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahwmitco.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzahwdbc-dbcco" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Database considerations for multithreaded programming</title>
</head>
<body id="rzahwdbc-dbcco"><a name="rzahwdbc-dbcco"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Database considerations for multithreaded programming</h1>
<div><p>You should consider these items when using databases in multithreaded
programs.</p>
<div class="section"><ul><li>Data definition language (DDL):<p>Many of the database configuration,
administration, and setup type interfaces are threadsafe. Database operations
that are threadsafe include: <span class="cmdname">Create File</span>, <span class="cmdname">Add
Member</span>, <span class="cmdname">Delete File</span>, and <span class="cmdname">Remove Member</span>.
Refer to CL Reference or use the <span class="cmdname">Display Command (DSPCMD)</span> command
to determine if a command is threadsafe. The online help information for that
command lists any necessary conditions for threadsafety that apply to a command.</p>
</li>
<li>Database record I/O:<p>The database protects the I/O operations
for the duration of the operation (read, update, insert, or delete). When
you share an open instance of a file among threads, you must serialize access
to the I/O feedback areas and I/O buffers to see valid information in these
areas. These areas are under application control, and the database cannot
protect them after the database operation has been completed.</p>
<p>An
example is a read operation. If thread 1 is in the process of a read operation
and thread 2 performs any I/O operation against the same open instance, thread
2 waits until thread 1 has completed the reading. The result of the read operation
in thread 1 is placed in the I/O buffer. When control returns to thread 1,
thread 2 begins its I/O operation. Without serialization, thread 2 can change
the information in the I/O buffer before thread 1 can view the result.</p>
<p>If
threads do not share an open instance of a file, no serialization is required.</p>
</li>
<li>Distributed files:<p>Access to distributed database files
used with the DB2<sup>®</sup> Multisystem
and access to distributed data management (DDM) files of type *SNA are not
threadsafe. Multithreaded jobs deny access to database files of these types.
These file types cannot be made threadsafe because intersystem communications
function (ICF) files and the entire Systems Network Architecture (SNA) layer
are not threadsafe. If an attempt is made to open one of these file types,
a CPF4380 message (<tt class="msgph">Open attributes not valid in a multithreaded process</tt>)
is sent to the function attempting to open the file. </p>
</li>
<li>Trigger programs:<p>You can fire trigger programs in a multithreaded job.
The same threadsafety restrictions apply to trigger programs as to any other
code that runs in a multithreaded job. Parameters on the <span class="cmdname">Add Physical
File Trigger (ADDPFTRG)</span> command allow for specification of the trigger's
threadsafety status and the action to take if the trigger is fired in a multithreaded
job. </p>
</li>
<li>Format selector programs:<p>For logical files with multiple formats, the
use of format selector programs is not threadsafe. You should not use format
selector programs in a multithreaded job.</p>
</li>
<li>Stored procedures:<p>DB2 Structured Query Language (SQL) stored-procedure
support provides a way for an SQL application to define and call an external
program though SQL statements. Stored procedures can be called in a multithreaded
job. The same thread safety restrictions apply to stored procedures as to
any other code that runs in a multithreaded job. Unlike trigger programs,
there is no way to specify the stored procedure's thread safety status and
the action to take if the stored procedure is called in a multithreaded job.</p>
</li>
<li>SQL statements:<p>The use of DDL SQL statements might not be threadsafe.
Data manipulation language (DML) statements are threadsafe. </p>
</li>
<li>Server mode for SQL:<p>Using the server mode for SQL is the preferred
method for accessing databases with multithreaded applications. A job can
use the server mode for SQL in order to manage multiple database connections
and transactions. When the application is using server mode for SQL, <span class="keyword">i5/OS™</span> uses the connections in the
job as a more encapsulated representation of the current database context
than previously permitted in <span class="keyword">i5/OS</span>.
It allows for connections to a database by multiple users, multiple connections
to a database by the same or different users, and the existence of multiple,
independent transactions by connections to a database. </p>
<p>Use one of the
following mechanisms to activate server mode for SQL before data access occurs
in the application:</p>
<ul><li>Use the Open Database Connectivity (ODBC) API, <span class="apiname">SQLSetEnvAttr()</span> and
set the SQL_ATTR_SERVER_MODE attribute to SQL_TRUE before doing any data access. </li>
<li>Use the <span class="cmdname">Change Job API, QWTCHGJB()</span> and set the 'Server
mode for Structured Query Language' key before doing any data access. </li>
<li>Use Java™ Database Connectivity (JDBC) to access
the database. JDBC automatically uses server mode to preserve required semantics
of JDBC. </li>
</ul>
<div class="p">Server mode for SQL behavior:<ul><li>For embedded SQL, each thread in a job is a separate transaction
that can be committed or rolled back, even if there are multiple connections
within that thread. </li>
<li>For ODBC, call level interface (CLI), and JDBC, each connection handle
represents a stand-alone connection to the database and can be committed and
used as a separate entity.</li>
</ul>
</div>
<p>The CLI for SQL is threadsafe. </p>
</li>
<li>Commitable transactions:<p>The introduction of threads does not change
the scope of committable transactions. You can scope committable units of
work to either a job-level commitment definition or an activation group-level
commitment definition. A thread commit or rollback operation commits or rolls-back
all operations done under the commitment definition. If you want an application
where each thread (or group of threads) has a separate committable transaction,
you must either use server mode for SQL or manage these transactions with
separate activation groups. </p>
</li>
</ul>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzahwrzahwe22e22rx.htm">Example: Work with local SQL databases in multithreaded Pthread programs</a></strong><br />
This example shows how to work with local SQL databases in multithreaded Pthread programs.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahwas4co.htm" title="All programs have at least one thread, referred to as the initial thread. In a program with multiple threads, each thread runs its code independently of the other threads in the program.">Threads on i5/OS</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rzahwdioco.htm" title="You can use the I/O feedback area of a database file to communicate results of I/O operations to the record I/O user. A typical application might have problems with thread safety because of the nature of the feedback area.">Database record I/O and thread safety</a></div>
<div><a href="rzahwrzahwe22e22rx.htm" title="This example shows how to work with local SQL databases in multithreaded Pthread programs.">Example: Work with local SQL databases in multithreaded Pthread programs</a></div>
<div><a href="rzahwexico.htm" title="The i5/OS registration facility allows you to define exit points for functions in an application and to register programs that run at those exit points.">Exit points</a></div>
<div><a href="rzahwmitco.htm" title="Database transactions in i5/OS are scoped to the job or the activation group.">Commit operations in multithreaded programs</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../rbam6/rbam6clmain.htm">CL Reference</a></div>
<div><a href="../db2/rbafzmstthreads.htm">Threads topic in SQL Reference</a></div>
<div><a href="../cli/rzadpkickoff.htm">SQL Call Level Interface (ODBC)</a></div>
</div>
</div>
</body>
</html>