je/docs/TransactionGettingStarted/txnconcurrency.html

374 lines
14 KiB
HTML
Raw Normal View History

2021-06-06 17:46:45 +00:00
<?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, Java Edition Transaction Processing" />
<link rel="up" href="index.html" title="Getting Started with Berkeley DB, Java Edition 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 xmlns="" class="navheader">
<div class="libver">
<p>Library Version 12.2.7.5</p>
</div>
<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 JE 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="jelock.html">JE Lock Management</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect2">
<a href="jelock.html#jelocktimeout">Managing JE Lock Timeouts</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="jelock.html#jedeadlock">Managing Deadlocks and other Lock Conflicts</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#serializable">Configuring Serializable 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>
</dl>
</div>
<p>
JE offers a great deal of support for multi-threaded
applications even when transactions are not in use. Many of JE's
handles are
thread-safe
and JE provides a
flexible locking subsystem for managing databases in a concurrent
application. Further, JE provides a robust mechanism for
detecting and responding to
<span>lock conflicts</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 JE
operations.
</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
JE 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 JE objects, see
<a class="xref" href="txnconcurrency.html#concurrenthandles" title="Which JE Handles are Free-Threaded">Which JE 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>
<li>
<p>
Lock Conflict
</p>
<p>
In JE, a lock conflict simply means that a thread of
control attempted to obtain a lock, but was unable to get
it before the lock timeout period expired. This may have
happened because a deadlock has occurred, or it might have
happened because another thread is taking too long to
complete a long-running database operation. Either way,
you do the same things in response to a lock conflict
as you do for a true deadlock. See <a class="xref" href="jelock.html" title="JE Lock Management">JE Lock Management</a> for more information.
</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 JE 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>
This class is free-threaded.
</p>
</li>
<li>
<p>
<code class="classname">Database</code>
<span>
and the DPL
<code class="classname">PrimaryIndex</code>
</span>
</p>
<p>
These classes are free-threaded.
</p>
</li>
<li>
<p>
<code class="classname">SecondaryDatabase</code>
and DPL <code class="classname">SecondaryIndex</code>
</p>
<p>
These classes are free-threaded.
</p>
</li>
<li>
<p>
<code class="classname">Cursor</code>
<span>
and the DPL
<code class="classname">EntityCursor</code>
</span>
</p>
<p>
If the cursor is a transactional cursor, it can be used by
multiple threads of control so long as the application
serializes access to the handle.
If the cursor is not a transactional cursor, it can not be
shared across multiple threads of control at all.
</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>
This class is free-threaded.
</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>