I am trying to use Berkeley with two different environment simultaneously in one program. But I am getting an error message of Databases left open. The first environment close with no error but the 2nd environment, having an error like this,
Exception in thread "main" java.lang.IllegalStateException: Unclosed Database: element_primary_key_index\\192.168.150.211\glassfish3\Berkeley\environment\Testing11
Unclosed Database: class_catalog\\192.168.150.211\glassfish3\Berkeley\environment\Testing11
Unclosed Database: element_database\\192.168.150.211\glassfish3\Berkeley\environment\Testing11
Databases left open: 3
Please someone help me with my problem. Thanks in advance.
This error simply means that you neglected to call Database.close for 3 databases before you called Environment.close. It is probably unrelated to the fact that you have two environments open.
Note that if you call Environment.openDatabase twice for the same database (in the same environment), you get two Database instances/handles, and both must be closed.
I am using the same close method for the two environment. The 1st closed the Databases and the environment with no problem but the 2nd environment had that error. I am sure that I close the Databases before closing the environment. But the error falls in closing the 2nd environment. The sequence is like this:
Open the 1st Environment --> Open the 2nd Environment --> Close the 1st Environment --> Close the 2nd Environment (Error falls in closing the 2nd Environment)
But if I am going to change the sequence like this:
Open the 1st Environment --> Close the 1st Environment --> Open the 2nd Environment --> Close the 2nd Environment
There is no error.
The one that I need is the 1st sequence. Thank you.
I see. By "environment" you mean environment handle. It is possible to open two separate environments, with different directories. It is also possible to open two Environment instances, or handles, for the same environment directory. You are talking about the latter.
I don't know of a problem like the one you describe. Could you please reproduce it with a small, standalone test program, that does nothing but open and close the databases and environment? If you can post that, we can take a look and see if you're doing something wrong, or there is a bug of some kind.
private static StoredClassCatalog classCatalog;
* Element Database.
private static Database elementDatabase;
* Element Database by Primary Key.
private static Database elementByPrimaryKeyDatabase;
private static Database catalogDatabase;
These fields are static -- they are globals -- so you're overwriting them when you open the 2nd environment.
I removed the STATIC but still doesnt work.
private StoredClassCatalog classCatalog;
private Database elementDatabase;
private Database elementByPrimaryKeyDatabase;
private Database catalogDatabase;
or even making the variables public.
public StoredClassCatalog classCatalog;
public Database elementDatabase;
public Database elementByPrimaryKeyDatabase;
public Database catalogDatabase;
Unclosed Database: element_primary_key_index\\192.168.160.184\glassfish\berkeley\environment\home\Multiple\Testing11
Unclosed Database: element_database\\192.168.160.184\glassfish\berkeley\environment\home\Multiple\Testing11
Unclosed Database: class_catalog\\192.168.160.184\glassfish\berkeley\environment\home\Multiple\Testing11
Databases left open: 3