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:

  • EnvironmentConfig.setAllowCreate()

    If true, the database environment is created when it is opened. If false, environment open fails if the environment does not exist. This property has no meaning if the database environment already exists. Default is false.

  • EnvironmentConfig.setReadOnly()

    If true, then all databases opened in this environment must be opened as read-only. If you are writing a multi-process application, then all but one of your processes must set this value to true. Default is false.

    You can also set this property using the je.env.isReadOnly parameter in your env_home/je.properties file.

  • EnvironmentConfig.setTransactional()

    If true, configures the database environment to support transactions. Default is false.

    You can also set this property using the je.env.isTransactional parameter in your env_home/je.properties file.

For example:

package je.gettingStarted;

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

import java.io.File;
     
...

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);
} 

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:

  • setCachePercent()

    Determines the percentage of JVM memory available to the JE cache. See Sizing the Cache for more information.

  • setCacheSize()

    Determines the total amount of memory available to the database cache. See Sizing the Cache for more information.

  • setTxnNoSync()

    Determines whether change records created due to a transaction commit are written to the backing log files on disk. A value of true causes the data to not be flushed to disk. See the Berkeley DB, Java Edition Getting Started with Transaction Processing guide.

  • setTxnWriteNoSync()

    Determines whether logs are flushed on transaction commit (the logs are still written, however). By setting this value to true, you potentially gain better performance than if you flush the logs on commit, but you do so by losing some of your transaction durability guarantees.

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 je.gettingStarted;

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

import java.io.File;


...

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
}