From 9c2f37c0ee2ee48b48988bee66e45b23ba51b3e2 Mon Sep 17 00:00:00 2001 From: Matt Freels Date: Sat, 4 Sep 2010 22:47:32 -0700 Subject: [PATCH] use a cancel-specific timer thread for SqlQuery cancelAsynchronously --- .../scala/com/twitter/querulous/query/SqlQuery.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/twitter/querulous/query/SqlQuery.scala b/src/main/scala/com/twitter/querulous/query/SqlQuery.scala index bbeb499..ac68c60 100644 --- a/src/main/scala/com/twitter/querulous/query/SqlQuery.scala +++ b/src/main/scala/com/twitter/querulous/query/SqlQuery.scala @@ -42,7 +42,12 @@ object NullValues { def apply(typeVal: Int) = nullTypes(typeVal) } +private object QueryCancellation { + val cancelTimer = new java.util.Timer("Query cancellation timer", true) +} + class SqlQuery(connection: Connection, query: String, params: Any*) extends Query { + import QueryCancellation._ val statement = buildStatement(connection, query, params: _*) @@ -78,9 +83,7 @@ class SqlQuery(connection: Connection, query: String, params: Any*) extends Quer override def run() { try { // FIXME make duration configurable - // FIXME use cancel specific timer, so that blocks in - // the global timeout thread do not affect cancel timeouts - Timeout(new com.twitter.xrayspecs.Duration(200)) { + Timeout(cancelTimer, new com.twitter.xrayspecs.Duration(200)) { try { // start by trying the nice way statement.cancel()