Debian Codegraph @

docs/gsg_txn/JAVA/txnconcurrency.html

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