GeeCON Prague 2014*
The moose likes JDBC and the fly likes Replacing setQueryTimeout(int timeoutValue) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Replacing setQueryTimeout(int timeoutValue)" Watch "Replacing setQueryTimeout(int timeoutValue)" New topic
Author

Replacing setQueryTimeout(int timeoutValue)

Serkan Demir
Ranch Hand

Joined: Feb 03, 2005
Posts: 61
Hi guys,

Many of you may use setQueryTimeout(int timeoutValue) method of PreparedStatement object for limiting the query time. This method internally creates a Timer thread, start it whenever query starts and stop and garbage it whenever query finishes. This is a useful method and prevents suspended threads which are waiting the query results.

However, our system needs high performance and responds more than 1000 request per second by querying database. Whenever i use setQueryTimeout method for each query, the amount of responses per second decreases and CPU usage increases (thread creation, starting are very expensive and I/O bound). Therefore i want to tune my application and by the way searching a replacement for setQueryTimeout method.

Is there anyone who comes with an idea?


A guy from Turkey<br /><a href="http://blogspot.serkandemir.com" target="_blank" rel="nofollow">http://blogspot.serkandemir.com</a>
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Try figuring out why you need to call setQueryTimeout() in the first place. Chances are it is a locking issue of some kind. Better transaction management and/or foreign key indexes, may vastly decrease locking such that the call is not needed.


My Blog: Down Home Country Coding with Scott Selikoff
Serkan Demir
Ranch Hand

Joined: Feb 03, 2005
Posts: 61
We have a worker pool which are only responsible for database transactions. Rarely, some workers are suspended while they are querying DB. I dont know the reason behind this suspension but it happens. Thus, we need to set some waiting limits for these suspended threads.
The reason for this query timeout is basically this.
 
GeeCON Prague 2014
 
subject: Replacing setQueryTimeout(int timeoutValue)