One question about setting query timeout. - Mailing list pgsql-jdbc
From | zhangyuanchao |
---|---|
Subject | One question about setting query timeout. |
Date | |
Msg-id | 52F84B99.20800@highgo.com.cn Whole thread Raw |
Responses |
Re: One question about setting query timeout.
|
List | pgsql-jdbc |
Hi,
I have a question about setting query timeout by jdbc.
When tested my application with Tomcat7.0 and loadrunner,my tomcat's configure file is like this:
<Resource ......
jdbcInterceptors="QueryTimeoutInterceptor(queryTimeout=600)"
....../>.
After setting like above ,tomcat will call the jdbc's setQueryTimeout function and set the query timeout to 600seconds for each statement.
Next,i start my test with 150 concurrency.After about 10 minutes later,i found the response time was much longer than before.At that moment,i found there were a lot of statement object in the heap memory of the JVM.And the JVM's gc could not clean these objects,because they were referenced by the TimerTask.So i read the source code of the jdbc and Timer class,i found the mainloop function of the Timer calss can cause the problem.This is the code of mainloop function in Timer class and i think the red colour text is that what cause the problem:
private void mainLoop() {
while (true) {
try {
TimerTask task;
boolean taskFired;
synchronized(queue) {
// Wait for queue to become non-empty
while (queue.isEmpty() && newTasksMayBeScheduled)
queue.wait();
if (queue.isEmpty())
break; // Queue is empty and will forever remain; die
// Queue nonempty; look at first evt and do the right thing
long currentTime, executionTime;
task = queue.getMin();
synchronized(task.lock) {
if (task.state == TimerTask.CANCELLED) {
queue.removeMin();
continue; // No action required, poll queue again
}
currentTime = System.currentTimeMillis();
executionTime = task.nextExecutionTime;
if (taskFired = (executionTime<=currentTime)) {
if (task.period == 0) { // Non-repeating, remove
queue.removeMin();
task.state = TimerTask.EXECUTED;
} else { // Repeating task, reschedule
queue.rescheduleMin(
task.period<0 ? currentTime - task.period
: executionTime + task.period);
}
}
}
if (!taskFired) // Task hasn't yet fired; wait
queue.wait(executionTime - currentTime);
}
if (taskFired) // Task fired; run it, holding no locks
task.run();
} catch(InterruptedException e) {
}
}
}
}
So,i want to ask if there is any solution for this problem.
Thanks very much.
I have a question about setting query timeout by jdbc.
When tested my application with Tomcat7.0 and loadrunner,my tomcat's configure file is like this:
<Resource ......
jdbcInterceptors="QueryTimeoutInterceptor(queryTimeout=600)"
....../>.
After setting like above ,tomcat will call the jdbc's setQueryTimeout function and set the query timeout to 600seconds for each statement.
Next,i start my test with 150 concurrency.After about 10 minutes later,i found the response time was much longer than before.At that moment,i found there were a lot of statement object in the heap memory of the JVM.And the JVM's gc could not clean these objects,because they were referenced by the TimerTask.So i read the source code of the jdbc and Timer class,i found the mainloop function of the Timer calss can cause the problem.This is the code of mainloop function in Timer class and i think the red colour text is that what cause the problem:
private void mainLoop() {
while (true) {
try {
TimerTask task;
boolean taskFired;
synchronized(queue) {
// Wait for queue to become non-empty
while (queue.isEmpty() && newTasksMayBeScheduled)
queue.wait();
if (queue.isEmpty())
break; // Queue is empty and will forever remain; die
// Queue nonempty; look at first evt and do the right thing
long currentTime, executionTime;
task = queue.getMin();
synchronized(task.lock) {
if (task.state == TimerTask.CANCELLED) {
queue.removeMin();
continue; // No action required, poll queue again
}
currentTime = System.currentTimeMillis();
executionTime = task.nextExecutionTime;
if (taskFired = (executionTime<=currentTime)) {
if (task.period == 0) { // Non-repeating, remove
queue.removeMin();
task.state = TimerTask.EXECUTED;
} else { // Repeating task, reschedule
queue.rescheduleMin(
task.period<0 ? currentTime - task.period
: executionTime + task.period);
}
}
}
if (!taskFired) // Task hasn't yet fired; wait
queue.wait(executionTime - currentTime);
}
if (taskFired) // Task fired; run it, holding no locks
task.run();
} catch(InterruptedException e) {
}
}
}
}
So,i want to ask if there is any solution for this problem.
Thanks very much.
pgsql-jdbc by date: