Edit: accuracy at build-deploy phase
I could not exactly reproduce your problem because I do not have an Eclipse environment. But:
- In the H2 documentation, it is clear that H2 accepts several simultaneous connections from the same JVM (link: Function - multiple connections in the h2database documentation)
- In the same documentation, it is clear that H2 does not accept direct connections from several processes (it is required that one of them acts as a server and the other a TCP connection) - this is not a problem for you, since your provider does not allow you to create other processes, but this is the cause of your mistakes.
- I could perform some tests that open the H2 database (in embedded mode) in one process with several connections and could handle a simultaneous query (5 connections, one query each, read 5 results, one row for each at a time)
- I could perform a similar test with two synchronized threads of one process (thread1 row1, thread2 row1, thread1 row2, thread2 row2 ...)
- as soon as the database is opened in another process (h2console), I get the error message
Database may be already in use: "Locked by another process"
So now I have good reason to say that the problem arises because Eclipse opens the database as part of the compilation-deployment process (I know that Netbeans can do this ...) or because it has an idea, allowing developper (you) to access the database directly (Netbeans can do this too ...). And you can have a race condition if the application starts before the Eclipse database closes.
Since you will not have Eclipse (or any other process accessing the database) in a production environment, this should not be a problem.
You can confirm that with these simple steps:
- create war under eclipse
- exit eclipse
- run a new instance of Tomcat (on your development machine)
- deploy the application under this instance and connect to it preferably from two different browsers to provide at least 2 connections.
An exception should not occur.
Optionnaly, if youβre used to it, you can emphasize the application using a tool like Apache JMeter
Even if Eclipse does not access the database on its own, a lot can happen during the deployment phase. An easy way to get rid of this would be to carefully terminate and deploy the application before deploying the new version in the development machine. If the problem no longer occurs, you should have no problems with production (as soon as you follow these steps).
source share