My web project is running in Tomcat 7. My server provider has already a MySQL server, however I want to use H2 as it give me a lot more flexibility and speed. My server provider has impose me a limitation that said that I should not start a new thread, doing so will automatically result in a tomcat stop.
My project is in an alpha near beta stage, so it is been tested locally. I am getting an SqlException Locked by another process often. This is happening when Tomcat updates the thread pool, most of the times happened when automatically publishing from Eclipse (which it is not a deal, as it won't happen on the server) but some times it just happens randomly.
My application doesn't access the database directly but through a wrapper that I am confident about it is not creating the issue but also prevents it to happened a lot.
It looks like Tomcat it is sending the thread that holds the connection to the background and any foreground thread will fail (my app it is database intensive). Open a connection in server mode will fix the problem, but it will run in a new process which I'm not allowed to. I will like to keep H2, so before I have to switch to MySQL I will need a solution for any of the following answers:
Note: I can not post any actual code. I am sure is not my application issue. I don't think it is necessary but I will write a description of how my wrapper handle the connection if required, but the problem has been identified as explained above.
Edit : precision on build-deploy step
I could not exactly reproduce your problem because I do not have an Eclipse environment. But :
Database may be already in use: "Locked by another process"
So I now have good reasons to say that the problem occurs because Eclipse opens the database as part of the compilation-deployment process (I know that Netbeans can do that ...), or because it has a view to allow the developper (you) to directly access the database (Netbeans can do that too ....). And you can have a race condition if the application starts before Eclipse closes the database.
As you won't have Eclipse (nor any other process accessing to the database) on your production environment, this should not be a problem.
You can confirm that with those simple steps :
The exception should not occurs.
Optionnaly, if you are used to that, you could stress the application using a tool like Apache JMeter
Even if Eclipse does not access the database by itself, many things may happen in deployement step. A simple way to get rid of that would be to carefully stop and undeploy the application before deploying a new version in the developpement machine. If the problem do not occur any longer, you should have no problem in production (as soon as you respect those steps).