The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Replacing setQueryTimeout(int timeoutValue)" Watch "Replacing setQueryTimeout(int timeoutValue)" New topic

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="" target="_blank" rel="nofollow"></a>
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

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.

[OCA 8 Book] [Blog]
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.
I agree. Here's the link:
subject: Replacing setQueryTimeout(int timeoutValue)
jQuery in Action, 3rd edition