1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Chapter 4. Concurrency</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
<link rel="up" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
<link rel="prev" href="maxtxns.html" title="Configuring the Transaction Subsystem" />
<link rel="next" href="blocking_deadlocks.html" title="Locks, Blocks, and Deadlocks" />
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Chapter 4. Concurrency</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="maxtxns.html">Prev</a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="blocking_deadlocks.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="chapter" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="txnconcurrency"></a>Chapter 4. Concurrency</h2>
</div>
</div>
</div>
<div class="toc">
<p>
<b>Table of Contents</b>
</p>
<dl>
<dt>
<span class="sect1">
<a href="txnconcurrency.html#concurrenthandles">Which DB Handles are Free-Threaded</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="blocking_deadlocks.html">Locks, Blocks, and Deadlocks</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2">
<a href="blocking_deadlocks.html#locks">Locks</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="blocking_deadlocks.html#blocks">Blocks</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="blocking_deadlocks.html#deadlocks">Deadlocks</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="sect1">
<a href="lockingsubsystem.html">The Locking Subsystem</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2">
<a href="lockingsubsystem.html#configuringlock">Configuring the Locking Subsystem</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="lockingsubsystem.html#configdeadlkdetect">Configuring Deadlock Detection</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="lockingsubsystem.html#deadlockresolve">Resolving Deadlocks</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="lockingsubsystem.html#setpriority">Setting Transaction Priorities</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="sect1">
<a href="isolation.html">Isolation</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2">
<a href="isolation.html#degreesofisolation">Supported Degrees of Isolation</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="isolation.html#dirtyreads">Reading Uncommitted Data</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="isolation.html#readcommitted">Committed Reads</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="isolation.html#snapshot_isolation">Using Snapshot Isolation</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="sect1">
<a href="txn_ccursor.html">Transactional Cursors and Concurrent Applications</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2">
<a href="txn_ccursor.html#cursordirtyreads">Using Cursors with Uncommitted Data</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="sect1">
<a href="readmodifywrite.html">Read/Modify/Write</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="txnnowait.html">No Wait on Blocks</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="reversesplit.html">Reverse BTree Splits</a>
</span>
</dt>
</dl>
</div>
<p>
DB offers a great deal of support for multi-threaded
<span>
and multi-process
</span>
applications even when transactions are not in use. Many of DB's
handles are
thread-safe<span>, or
can be made thread-safe by providing the appropriate flag at handle creation time,</span>
and DB provides a
flexible locking subsystem for managing databases in a concurrent
application. Further, DB provides a robust mechanism for
detecting and responding to
<span>deadlocks</span>.
All of these concepts are
explored in this chapter.
</p>
<p>
Before continuing, it is useful to define a few terms that will appear
throughout this chapter:
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>
<span class="emphasis"><em>Thread of control</em></span>
</p>
<p>
Refers to a thread that is performing work in your application.
Typically, in this book that thread will be performing DB
operations.
</p>
<p>
Note that this term can also be taken to mean a separate process
that is performing work — DB supports multi-process
operations on your databases.
</p>
</li>
<li>
<p>
<span class="emphasis"><em>Locking</em></span>
</p>
<p>
When a thread of control obtains
access to a shared resource, it is said to be
<span class="emphasis"><em>locking</em></span> that resource. Note that
DB supports both exclusive and non-exclusive locks. See
<a class="xref" href="blocking_deadlocks.html#locks" title="Locks">Locks</a> for more information.
</p>
</li>
<li>
<p>
<span class="emphasis"><em>Free-threaded</em></span>
</p>
<p>
Data structures and objects are free-threaded if they can be
shared across threads of control without any explicit locking on
the part of the application. Some books, libraries, and
programming languages may use the term
<span class="emphasis"><em>thread-safe</em></span> for data structures or objects
that have this characteristic. The two terms mean the
same thing.
</p>
<p>
For a description of free-threaded DB objects, see
<a class="xref" href="txnconcurrency.html#concurrenthandles" title="Which DB Handles are Free-Threaded">Which DB Handles are Free-Threaded</a>.
</p>
</li>
<li>
<p>
<span class="emphasis"><em>Blocked</em></span>
</p>
<p>
When a thread cannot obtain a lock because some other
thread already holds a lock on that object, the lock
attempt is said to be <span class="emphasis"><em>blocked</em></span>. See
<a class="xref" href="blocking_deadlocks.html#blocks" title="Blocks">Blocks</a> for more information.
</p>
</li>
<li>
<p>
<span class="emphasis"><em>Deadlock</em></span>
</p>
<p>
Occurs when two or more threads of control attempt to access conflicting resource in such a way as none
of the threads can any longer make further progress.
</p>
<p>
For example, if Thread A is blocked waiting for a resource held by Thread
B, while at the same time Thread B is blocked waiting for a
resource held by Thread A, then neither thread can make any
forward progress. In this situation, Thread A and Thread B
are said to be <span class="emphasis"><em>deadlocked.</em></span>
</p>
<p>
For more information, see <a class="xref" href="blocking_deadlocks.html#deadlocks" title="Deadlocks">Deadlocks</a>.
</p>
</li>
</ul>
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="concurrenthandles"></a>Which DB Handles are Free-Threaded</h2>
</div>
</div>
</div>
<p>
The following describes to what extent and under what conditions
individual handles are free-threaded.
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>
<code class="classname">Environment</code>
<span>
and the DPL
<code class="classname">EntityStore</code>
</span>
</p>
<p>
Free-threaded so long as
<span>
<code class="methodname">EnvironmentConfig.setThreaded()</code>
is set to <code class="literal">true</code>.
</span>
</p>
</li>
<li>
<p>
<code class="classname">Database</code>
<span>
and the DPL
<code class="classname">PrimaryIndex</code>
</span>
</p>
<p>
Free-threaded so long as
<span>
the database
<span>
or DPL <code class="classname">PrimaryIndex</code>
</span>
is opened in a free-threaded environment.
</span>
</p>
</li>
<li>
<p>
<code class="classname">SecondaryDatabase</code>
and DPL <code class="classname">SecondaryIndex</code>
</p>
<p>
Same conditions apply as for <code class="classname">Database</code>
and <code class="classname">PrimaryIndex</code> handles.
</p>
</li>
<li>
<p>
<code class="classname">Cursor</code>
<span>
and the DPL
<code class="classname">EntityCursor</code>
</span>
</p>
<p>
Cursors are not free-threaded. However, they
can be used by multiple threads of control so
long as the application serializes access to the handle.
</p>
</li>
<li>
<p>
<code class="classname">SecondaryCursor</code>
</p>
<p>
Same conditions apply as for <code class="classname">Cursor</code>
handles.
</p>
</li>
<li>
<p>
<code class="classname">Transaction</code>
</p>
<p>
Access must be serialized by the application across threads of control.
</p>
</li>
</ul>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
All other classes found in the DPL
(<code class="literal">com.sleepycat.persist.*</code>) and not
mentioned above are free-threaded.
</p>
<p>
All classes found in the bind APIs (<code class="literal">com.sleepycat.bind.*</code>) are free-threaded.
</p>
</div>
</div>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="maxtxns.html">Prev</a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="blocking_deadlocks.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Configuring the Transaction Subsystem </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Locks, Blocks, and Deadlocks</td>
</tr>
</table>
</div>
</body>
</html>
|