I know I can just slap a synchronized block around these two methods to make it bulletproof, but there are two problems with this: (1) synchronized is slow and Derby's shutdown is not fast at all... (2) I don't know what other apps might be open in the same JVM at the same.
I'm not sure you can avoid the performance cost, given the needs of your application. I'm always more comfortable getting the correct behavior first, then dealing with the implications once it's reliably running. I think you may have to do slightly more than just make two methods synchronized; it isn't exactly clear to me which two methods you mean. I might try: - make the Database class have two public methods "Open" and "Close". - in Open, call DriverManager.getConnection and increment your in-use count - in Close, close the connection, decrement your in-use count, and shutdown the database when it goes to zero - make Open and Close synchronized Regarding other apps in the same JVM, is that truly a concern? I'm not sure how your app is packaged, but it seems unlikely to me that some other arbitrary body of Java code is going to try to open one of your own databases. How would that code even know what connection URL to use? thanks, bryan
