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