Berkeley DB Reference Version 5.3.35

Environment Properties

The EnvironmentConfig Class

EnvironmentMutableConfig

You set properties for the Environment using the EnvironmentConfig class. You can also set properties for a specific Environment instance using EnvironmentMutableConfig.

The EnvironmentConfig Class

The EnvironmentConfig class makes a large number of fields and methods available to you. Describing all of these tuning parameters is beyond the scope of this manual. However, there are a few properties that you are likely to want to set. They are described here.

Note that for each of the properties that you can commonly set, there is a corresponding getter method. Also, you can always retrieve the EnvironmentConfig object used by your environment using the Environment.getConfig() method.

You set environment configuration parameters using the following methods on the EnvironmentConfig class:

For example:

package db.gettingStarted;

import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;

import java.io.File;
import java.io.FileNotFoundException;
     
...

Environment myDatabaseEnvironment = null;
try {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    myDatabaseEnvironment = 
        new Environment(new File("/export/dbEnv"), envConfig);
} catch (DatabaseException dbe) {
   System.err.println(dbe.toString());
   System.exit(1);
} catch (FileNotFoundException fnfe) {
    System.err.println(fnfe.toString());
    System.exit(-1);
} 

EnvironmentMutableConfig

EnvironmentMutableConfig manages properties that can be reset after the Environment object has been constructed. In addition, EnvironmentConfig extends EnvironmentMutableConfig, so you can set these mutable properties at Environment construction time if necessary.

The EnvironmentMutableConfig class allows you to set the following properties:

There is also a corresponding getter method (getTxnNoSync()). Moreover, you can always retrieve your environment's EnvironmentMutableConfig object by using the Environment.getMutableConfig() method.

For example:

package db.gettingStarted;

import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentMutableConfig;

import java.io.File;
import java.io.FileNotFoundException;

...

try {
    Environment myEnv = new Environment(new File("/export/dbEnv"), null);
    EnvironmentMutableConfig envMutableConfig = 
        new EnvironmentMutableConfig();
    envMutableConfig.setTxnNoSync(true);
    myEnv.setMutableConfig(envMutableConfig); 
} catch (DatabaseException dbe) {
    // Exception handling goes here
} catch (FileNotFoundException fnfe) {
    // Exception handling goes here
}