I'm writing a small Java-based server around Tokyo Cabinets JNI-bindings, and I am a bit confused regarding opening and closing of the db file. The server is multi-threaded, and I'm therefore wondering if it is best to open the db file upon start-up and then let the threads use get/put unsynchronized (I think that the tokyo docs state that the bindings are thread-safe) - but what happends if the server crashes without closing the db file, can it lead to data corruption? The second alternative is to create a synchronized method around get/put in which I first open the db file, get/put, and finally close it. But will the latter solution have a negative impact on performance?
What is the preferred way to let a multi-threaded application interact with tokyo cabinet?