5 Replies Latest reply on Dec 3, 2012 1:14 AM by 977385

    In memory database usage


      I am trying to create an in-memory database (I do not need any files -log or database- to be stored on disk) , do calculations, save the calculations and terminate it. I cannot seem to locate an example in JE to create an in-memory database. As far as I get from the documentation this should be possible but I was not able to change examples to fit my need. Can you please point me to a document or an example that covers this?

        • 1. Re: In memory database usage

          Where did you see in the documentation that in-memory databases are supported in JE? They are not.

          Temporary databases are supported, but they will be written to disk when the cache overflows. See DatabaseConfig.setTemporary.

          For more details, search the forum for "in memory" (with the quotes).

          1 person found this helpful
          • 2. Re: In memory database usage
            I presumed that this meant in-memory (from ~GettingStartedGuide/usingDbt.html#datapersist):

            If you do not want to use transactions, then the assumption is that your data is of a nature that it need not exist the next time your application starts. You may want this if, for example, you are using JE to cache data relevant only to the current application runtime.

            I changed an example to get rid of transactional code and save 1MM records into the table. It's not saving the data that I am saving into the database. It does it when database is opened and closed. This must be what is described in the above paragraph. I understand that if BDB consumes all memory there will be caching for this operation.

            EnvironmentConfig envConfig = new EnvironmentConfig();
            Environment exampleEnv = new Environment(envDir, envConfig);
            DatabaseConfig dbConfig = new DatabaseConfig();
            Database exampleDb = exampleEnv.openDatabase(null, "a", dbConfig);
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry dataEntry = new DatabaseEntry();
            Map<Integer,Integer> entries=new TreeMap<Integer,Integer>();
                 for (int i = offset; i < numRecords + offset; i++) {
                      IntegerBinding.intToEntry(i, keyEntry);
                      IntegerBinding.intToEntry(i+1, dataEntry);
                      OperationStatus status = exampleDb.put(null, keyEntry, dataEntry);
                      if (status != OperationStatus.SUCCESS) {
                      throw new RuntimeException("Data insertion got status " +
            • 3. Re: In memory database usage
              Hi again,

              Durability, transactions, temporary databases and in-memory databases are all different things, and each is a topic all on its own. Rather than try to describe all of that, it would help if you could describe exactly what you want to do, and why -- what is the purpose of your questions -- so I can better give you the information you need.

              I noticed in your code example, you're using temporary databases -- you're calling DatabaseConfig.setTemporary(true). If you don't need the data to be persistent, this is the right thing to do. If you're asking how temporary databases work, see:

              However, you should also ask yourself why you're using a database. Why not just just a HashMap or TreeMap? If you can answer this question, it will help to understand the problem you're trying to solve.

              • 4. Re: In memory database usage
                You may want to look at Berkeley DB (a product very similar to Berkeley DB Java Edition, but distinct), which does support pure in-memory databases as well as a Java API.

                you look up the programmer reference for Berkeley DB here: http://docs.oracle.com/cd/E17076_02/html/programmer_reference/BDB_Prog_Reference.pdf Search for "Memory-only or Flash configurations".

                If you decide to go ahead with Berkeley DB, and have questions, you should post them to the Berkeley DB forum (Berkeley DB

                Hope this is helpful.

                Warm regards.
                1 person found this helpful
                • 5. Re: In memory database usage
                  Thanks for taking time. The reason I've looked into BDB JE was the fact that it is in-process. I'll read a bit more on when it starts caching to find out if it fits my use case.