I have a requirement where in if my query execution takes more than two minutes to execute I have throw an execption and redirect user to an error page. I tried using the setQueryTimeout method of Statement but it is not working. Any other approach i can use to achieve this?
You can use OracleConnectionCacheManager to create a connection pool with a TimeToLiveTimeout so that any connection taken from the pool will be logically closed within that stipulated amount of time.
You can see his link for further reference:
This time out is usually not recommended as the implementation of this timeout will some times cause the JVM to hang.
If you want to do it completely in java, you can use a process similar to this-
1. Get the connection and pass it to a runnable class and start the thread.
2. In the thread, wait for two minutes and close the connection.
3. After starting the thread, call the method that executes the query. Pass the same connection to the method.
4. If in 2 mintues the method that executes the query is not completed, the connection is closed and you will get an SQLExcetption in the method. You can handle it as you like.
5. If the execution is completed, closing the connection that is already closed does not matter.
Hope it helps.
They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Joined: Aug 27, 2003
thanks sandeep, i will go for the java approach that you suggested.