Opening database managing handles
<p>I am using berkeley database....  </p>

<p>Generally at this type of database you open an environment which is a bunch of files to control locking and transactions etc and then you open your database in this environment...  </p>

<p>The problem is that there are LOTS of databases to open....<br>
The method to open a database is    <code>opendatabase()</code><br>
However opening and closing the database always is slow... The documentation says</p>

<blockquote>
  <p>Opening a database is a relatively
  expensive operation, and maintaining a
  set of open databases will normally be
  preferable to repeatedly opening and
  closing the database for each new
  query.</p>
</blockquote>

<p>The problem is how to maintain that set ??????<br>
A simple solution i thought was lazy loading </p>

<pre><code> private static Database db;
     public   CustomerDAO() {
            if (db == null) {
                try {
                    DatabaseConfig dbConfig = new DatabaseConfig();
                    dbConfig.setAllowCreate(true);
                    dbConfig.setType(DatabaseType.BTREE);
                    db = BDBEnvironment.DEFAULT.getEnvironment().openDatabase(null, "C:\\xxxx\\CUSTOMERS",
                            null, dbConfig); 
</code></pre>

<p>But this has a problem with double check locking.. Right???<br>
Another issue is that i want to have a default file name or a user specified one..  Of course it is easy to create a DatabaseManager but always double check lock issue would occur.<br>
Any ideas how to maintain a set of database handles??</p>
