Debian Codegraph @

docs/gsg_txn/JAVA/maxtxns.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>Configuring the Transaction Subsystem</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="usingtxns.html" title="Chapter 3. Transaction Basics" />
11 <link rel="prev" href="txnindices.html" title="Secondary Indices with Transaction Applications" />
12 <link rel="next" href="txnconcurrency.html" title="Chapter 4. Concurrency" />
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">Configuring the Transaction Subsystem</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="txnindices.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. Transaction Basics</th>
26 <td width="20%" align="right"> <a accesskey="n" href="txnconcurrency.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="maxtxns"></a>Configuring the Transaction Subsystem</h2>
36 </div>
37 </div>
38 </div>
39 <p>
40 Most of the configuration activities that you need to perform
41 for your transactional DB application will involve the
42 locking and logging subsystems. See
43 <a class="xref" href="txnconcurrency.html" title="Chapter 4. Concurrency">Concurrency</a>
44 and
45 <a class="xref" href="filemanagement.html" title="Chapter 5. Managing DB Files">Managing DB Files</a>
46 for details.
47 </p>
48 <p>
49 However, there are a couple of things that you can do to
50 configure your transaction subsystem directly. These things
51 are:
52 </p>
53 <div class="itemizedlist">
54 <ul type="disc">
55 <li>
56 <span>
57 <p>
58
59 <span>
60 Configure
61 </span>
62
63 the maximum number of simultaneous
64 transactions needed by your application.
65 In general, you should not need to do this unless you
66 use deeply nested transactions or you have many threads all
67 of which have active transactions. In addition, you may
68 need to configure a higher maximum number of transactions if you
69 are using snapshot isolation. See
70 <a class="xref" href="isolation.html#sisolation_maxtxn" title="Snapshot Isolation Transactional Requirements">Snapshot Isolation Transactional Requirements</a>
71 for details.
72 </p>
73 <p>
74 By default, your application can support 20 active
75 transactions.
76 </p>
77 <p>
78 You can set the maximum number of simultaneous
79 transactions supported by your application using
80
81 <span>
82 <code class="methodname">EnvironmentConfig.setTxnMaxActive()</code>.
83 </span>
84 </p>
85 <p>
86 If your application has exceeded this maximum value,
87 then any attempt to begin a new transaction will fail.
88 </p>
89 <p>
90 This value can also be set using the
91 <code class="literal">DB_CONFIG</code> file's
92 <code class="literal">set_tx_max</code> parameter. Remember that
93 the <code class="literal">DB_CONFIG</code> must reside in your
94 environment home directory.
95 </p>
96 </span>
97 </li>
98 <li>
99 <span>
100 <p>
101 <span>
102 Configure the timeout value for your transactions.
103 </span>
104
105
106 This value represents the longest period of time a
107 transaction can be active. Note, however, that
108 transaction timeouts are checked only when DB
109 examines its lock tables for blocked locks
110 (see <a class="xref" href="blocking_deadlocks.html" title="Locks, Blocks, and Deadlocks">Locks, Blocks, and Deadlocks</a>
111 for more information). Therefore, a transaction's timeout can
112 have expired, but the application will not be notified until DB
113 has a reason to examine its lock tables.
114 </p>
115 <p>
116 Be aware that some transactions may be
117 inappropriately timed out before the transaction has a
118 chance to complete. You should therefore use this
119 mechanism only if you know your application
120 might have unacceptably long transactions and
121 you want to make sure your application will
122 not stall during their execution.
123 (This might happen if, for example, your
124 transaction blocks or requests too much
125 data.)
126 </p>
127 <p>
128 Note that by default transaction timeouts are set to 0 seconds, which means that they never time
129 out.
130 </p>
131 <p>
132 To set the maximum timeout value for your transactions,
133 use the
134
135
136 <span><code class="methodname">EnvironmentConfig.setTxnTimeout()</code></span>
137 method. This method configures the entire
138 environment; not just the handle used to set the
139 configuration. Further, this value may
140 be set at any time during the application's
141 lifetime. <span>(Use
142 <code class="methodname">Environment.setConfig()</code> to
143 set this value after the environment has been
144 opened.)</span>
145 </p>
146 <p>
147 This value can also be set using the
148 <code class="literal">DB_CONFIG</code> file's
149 <code class="literal">set_txn_timeout</code> parameter.
150 </p>
151
152 </span>
153 </li>
154 </ul>
155 </div>
156 <p>
157 For example:
158 </p>
159 <pre class="programlisting">package db.txn;
160
161 import com.sleepycat.db.Environment;
162 import com.sleepycat.db.EnvironmentConfig;
163 import com.sleepycat.db.LockDetectMode;
164
165 import java.io.File;
166 import java.io.FileNotFoundException;
167
168 ...
169
170 Environment myEnv = null;
171 try {
172 EnvironmentConfig myEnvConfig = new EnvironmentConfig();
173 myEnvConfig.setTransactional(true);
174 myEnvConfig.setInitializeCache(true);
175 myEnvConfig.setInitializeLocking(true);
176 myEnvConfig.setInitializeLogging(true);
177
178 // Configure a maximum transaction timeout of 1 second.
179 myEnvConfig.setTxnTimeout(1000000);
180 // Configure 40 maximum transactions.
181 myEnv.setTxnMaxActive(40);
182
183 myEnv = new Environment(new File("/my/env/home"),
184 myEnvConfig);
185
186 // From here, you open your databases (or store), proceed with your
187 // database or store operations, and respond to deadlocks as is
188 // normal (omitted for brevity).
189
190 ...</pre>
191 </div>
192 <div class="navfooter">
193 <hr />
194 <table width="100%" summary="Navigation footer">
195 <tr>
196 <td width="40%" align="left"><a accesskey="p" href="txnindices.html">Prev</a> </td>
197 <td width="20%" align="center">
198 <a accesskey="u" href="usingtxns.html">Up</a>
199 </td>
200 <td width="40%" align="right"> <a accesskey="n" href="txnconcurrency.html">Next</a></td>
201 </tr>
202 <tr>
203 <td width="40%" align="left" valign="top">Secondary Indices with Transaction Applications </td>
204 <td width="20%" align="center">
205 <a accesskey="h" href="index.html">Home</a>
206 </td>
207 <td width="40%" align="right" valign="top"> Chapter 4. Concurrency</td>
208 </tr>
209 </table>
210 </div>
211 </body>
212 </html>