Environment Properties

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.setCachePercent()

    Sets the percentage of the JVM memory set aside for the in-memory cache. If a non-zero value is set for EnvironmentConfig.setCacheSize(), this percentage value is not used to determine the cache size. Further, this percentage is used only for those JVMs that are capable of reporting the maximum requested memory via Runtime.maxMemory().

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

  • EnvironmentConfig.setCacheSize()

    Sets the amount of memory in bytes allowed for the in-memory cache. If a non-zero value is set for this property, then any percentage set for EnvironmentConfig.setCachePercent() is ignored. See Sizing the Cache for advice on setting your cache size.

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

  • 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:

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

Environment myDatabaseEnvironment;
try {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setCacheSize(134217728); // 128 x 1024 x 1024
    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 just one property:

  • 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 change records to not be flushed to disk. See Committing and Aborting Transactions for more information.

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

For example:

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

...

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