2

Is there a way to do non-blocking actions on the java interface of Berkeley DB and get the status and result of the action using a Future or something similar (like getting a result of a Callable using a Future)?

I don't want the thread calling the DB to be blocked until the DB action is done.

Yoav Slomka
  • 372
  • 2
  • 10

2 Answers2

1

from what I have seen in the API documentation, Berkeley DB JE does not have an asynchronous API. every call to the DB will block the calling thread until the action is done.

Yoav Slomka
  • 372
  • 2
  • 10
0

Yes, you can do it, as with any DB or resource, by simply creating a thread and starting it.

Runnable r = new Runnable() {
    public void run() {
        // call the DB
        // call your callback to run other tasks after with the result
    }
};
new Thread(r).start();

That's the standard way, in Java, to do asynchronous actions. You're in charge of the threads, contrary to javascript to which you seem to refer.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 1
    thanks, but I wanted to know if Berkeley DB has non-blocking methods. I want to commit data to the DB without blocking my thread until the write is over and check if the action has finished and if it was successful using a Future. – Yoav Slomka Sep 30 '12 at 08:41