• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/docs/gsg_txn/JAVA/
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��6.��Summary and Examples</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="logconfig.html" title="Configuring the Logging Subsystem" />
12    <link rel="next" href="txnexample_java.html" title="Base API Transaction Example" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Chapter��6.��Summary and Examples</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="logconfig.html">Prev</a>��</td>
22          <th width="60%" align="center">��</th>
23          <td width="20%" align="right">��<a accesskey="n" href="txnexample_java.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="chapter" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title"><a id="wrapup"></a>Chapter��6.��Summary and Examples</h2>
33          </div>
34        </div>
35      </div>
36      <div class="toc">
37        <p>
38          <b>Table of Contents</b>
39        </p>
40        <dl>
41          <dt>
42            <span class="sect1">
43              <a href="wrapup.html#anatomy">Anatomy of a Transactional Application</a>
44            </span>
45          </dt>
46          <dt>
47            <span class="sect1">
48              <a href="txnexample_java.html">Base API Transaction Example</a>
49            </span>
50          </dt>
51          <dd>
52            <dl>
53              <dt>
54                <span class="sect2">
55                  <a href="txnexample_java.html#txnguideexample">TxnGuide.java</a>
56                </span>
57              </dt>
58              <dt>
59                <span class="sect2">
60                  <a href="txnexample_java.html#payloaddata">PayloadData.java</a>
61                </span>
62              </dt>
63              <dt>
64                <span class="sect2">
65                  <a href="txnexample_java.html#dbwriter">DBWriter.java</a>
66                </span>
67              </dt>
68            </dl>
69          </dd>
70          <dt>
71            <span class="sect1">
72              <a href="txnexample_dpl.html">DPL Transaction Example</a>
73            </span>
74          </dt>
75          <dd>
76            <dl>
77              <dt>
78                <span class="sect2">
79                  <a href="txnexample_dpl.html#txnguideexample_dpl">TxnGuide.java</a>
80                </span>
81              </dt>
82              <dt>
83                <span class="sect2">
84                  <a href="txnexample_dpl.html#payloaddataentity">PayloadDataEntity.java</a>
85                </span>
86              </dt>
87              <dt>
88                <span class="sect2">
89                  <a href="txnexample_dpl.html#storewriter">StoreWriter.java</a>
90                </span>
91              </dt>
92            </dl>
93          </dd>
94          <dt>
95            <span class="sect1">
96              <a href="inmem_txnexample_java.html">Base API In-Memory Transaction Example</a>
97            </span>
98          </dt>
99        </dl>
100      </div>
101      <p>
102        Throughout this manual we have presented the concepts and
103        mechanisms that you need to provide transactional protection for
104        your application. In this chapter, we summarize these
105        mechanisms, and we provide a complete example of a multi-threaded
106        transactional DB application.
107  </p>
108      <div class="sect1" lang="en" xml:lang="en">
109        <div class="titlepage">
110          <div>
111            <div>
112              <h2 class="title" style="clear: both"><a id="anatomy"></a>Anatomy of a Transactional Application</h2>
113            </div>
114          </div>
115        </div>
116        <p>
117        Transactional applications are characterized by performing the
118        following activities:
119    </p>
120        <div class="orderedlist">
121          <ol type="1">
122            <li>
123              <p>
124                Create your environment handle.
125            </p>
126            </li>
127            <li>
128              <p>
129                Open your environment, specifying that the following
130                subsystems be used:
131            </p>
132              <div class="itemizedlist">
133                <ul type="disc">
134                  <li>
135                    <p>
136                        Transactional Subsystem (this also initializes the
137                        logging subsystem).
138                    </p>
139                  </li>
140                  <li>
141                    <p>
142                        Memory pool (the in-memory cache).
143                    </p>
144                  </li>
145                  <li>
146                    <p>
147                        Logging subsystem.
148                    </p>
149                  </li>
150                  <li>
151                    <p>
152                        Locking subsystem (if your application is multi-process or multi-threaded).
153                    </p>
154                  </li>
155                </ul>
156              </div>
157              <p>
158                It is also highly recommended that you run normal recovery 
159                upon first environment open. Normal recovery examines only those logs required
160                to ensure your database files are consistent relative to the information found in your
161                log files.
162            </p>
163            </li>
164            <li>
165              <p>
166                Optionally spawn off any utility threads that you might need. Utility
167                threads can be used to run checkpoints periodically, or to
168                periodically run a deadlock detector if you do not want to
169                use DB's built-in deadlock detector.
170            </p>
171            </li>
172            <li>
173              <p>
174                If you are using the base API, open whatever database handles
175                that you need. Otherwise, open your store such that it is
176                configured for transactions.
177            </p>
178            </li>
179            <li>
180              <p>
181                Spawn off worker threads. How many of these you need and
182                how they split their DB workload is entirely up to your
183                application's requirements. However, any worker threads
184                that perform write operations will do the following:
185            </p>
186              <div class="orderedlist">
187                <ol type="a">
188                  <li>
189                    <p>
190                        Begin a transaction.
191                    </p>
192                  </li>
193                  <li>
194                    <p>
195                        Perform one or more read and write
196                        operations.
197                    </p>
198                  </li>
199                  <li>
200                    <p>
201                        Commit the transaction if all goes well.
202                    </p>
203                  </li>
204                  <li>
205                    <p>
206                        Abort and retry the operation if a deadlock is
207                        detected.
208                    </p>
209                  </li>
210                  <li>
211                    <p>
212                        Abort the transaction for most other errors.
213                    </p>
214                  </li>
215                </ol>
216              </div>
217            </li>
218            <li>
219              <p>
220                On application shutdown:
221            </p>
222              <div class="orderedlist">
223                <ol type="a">
224                  <li>
225                    <p>
226                        Make sure there are no opened cursors.
227                    </p>
228                  </li>
229                  <li>
230                    <p>
231                        Make sure there are no active transactions. Either
232                        abort or commit all transactions before shutting
233                        down.
234                    </p>
235                  </li>
236                  <li>
237                    <p>
238                            Close your databases or store.
239                    </p>
240                  </li>
241                  <li>
242                    <p>
243                        Close your environment.
244                    </p>
245                  </li>
246                </ol>
247              </div>
248            </li>
249          </ol>
250        </div>
251        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
252          <h3 class="title">Note</h3>
253          <p>
254                Robust DB applications should monitor their worker threads to
255            make sure they have not died unexpectedly. If a thread does
256            terminate abnormally, you must shutdown all your worker threads
257            and then run normal recovery (you will have to reopen your
258            environment to do this). This is the only way to clear any
259            resources (such as a lock or a mutex) that the abnormally
260            exiting worker thread might have been holding at the time that
261            it died.
262        </p>
263          <p>
264            Failure to perform this recovery can cause your
265            still-functioning worker threads to eventually block forever
266            while waiting for a lock that will never be released.
267        </p>
268        </div>
269        <p>
270        In addition to these activities, which are all entirely handled by
271        code within your application, there are some administrative
272        activities that you should perform:
273    </p>
274        <div class="itemizedlist">
275          <ul type="disc">
276            <li>
277              <p>
278                Periodically checkpoint your application. Checkpoints will
279                reduce the time to run recovery in the event that one is
280                required. See <a class="xref" href="filemanagement.html#checkpoints" title="Checkpoints">Checkpoints</a>
281                for details.
282            </p>
283            </li>
284            <li>
285              <p>
286                Periodically back up your database and log files. This is
287                required in order to fully obtain the durability guarantee
288                made by DB's transaction ACID support. See
289                <a class="xref" href="backuprestore.html" title="Backup Procedures">Backup Procedures</a>
290                for more information.
291            </p>
292            </li>
293            <li>
294              <p>
295                You may want to maintain a hot failover if 24x7 processing
296                with rapid restart in the face of a disk hit is important
297                to you. See <a class="xref" href="hotfailover.html" title="Using Hot Failovers">Using Hot Failovers</a>
298                for more information.
299            </p>
300            </li>
301          </ul>
302        </div>
303      </div>
304    </div>
305    <div class="navfooter">
306      <hr />
307      <table width="100%" summary="Navigation footer">
308        <tr>
309          <td width="40%" align="left"><a accesskey="p" href="logconfig.html">Prev</a>��</td>
310          <td width="20%" align="center">��</td>
311          <td width="40%" align="right">��<a accesskey="n" href="txnexample_java.html">Next</a></td>
312        </tr>
313        <tr>
314          <td width="40%" align="left" valign="top">Configuring the Logging Subsystem��</td>
315          <td width="20%" align="center">
316            <a accesskey="h" href="index.html">Home</a>
317          </td>
318          <td width="40%" align="right" valign="top">��Base API Transaction Example</td>
319        </tr>
320      </table>
321    </div>
322  </body>
323</html>
324