• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setQueryTimeout not working

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?

I am using Oracle 10g as my DB.

Thanks.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sahil Sharma
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks sandeep, i will go for the java approach that you suggested.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic