1

Question/Environment

The goal of my web application is to be a handy interface to the database at our company.

I'm using:

  • Scalatra (as minimal web framework)
  • Jetty (as servlet container)
  • SBT (Simple Build Tool)
  • JDBC (to interface with the database)

One of the requirements is that each user can manage a number of concurrent queries, and that even when he/she logs off, the queries keep running and can be retrieved later on (or their completion status checked if they stopped for any reason).

I suppose queries will likely have to run in their own seperate thread.

I'm not even sure if this issue is orthogonal or not to connection pooling (which I'm definitely going to use, BoneCP and C3PO seem nice).

Summary

In short: I need to have very fine-grained control over the lifetime of database requests, and they cannot be bound to the servlet lifetime

What ways are there to fulfill my requirements? I've searched quite a bit on google and stack overflow and haven't found anything that addresses my problem, is it even possible?

Aktau
  • 1,847
  • 21
  • 30

1 Answers1

2

What is missing from your stack is a scheduler. e.g http://www.quartz-scheduler.org/

A rough explanation:

  • Your connection pool (eg C3P0) will be bound to the application's lifecycle.
  • Your servlets will be sending query requests to the scheduler (these will be associated to the user requesting the query).
  • The scheduler will be executing queries as soon as possible, by using connections from the connection pool. It may also do so in a synchronized/serialized order (for each user).
  • The user will be able to see all query requests associated with him, probably with status (pending, completed with results etc).
cherouvim
  • 31,725
  • 15
  • 104
  • 153
  • Thanks for the answer, I must admit that it indeed looks like I could make use of some sort of scheduler! I'm not yet marking the answer as the correct one because there may be alternatives and I would like to hear of them also. Any experiences integrating with Jetty and/or Scalatra? (a cursory web search seems to indicate that it will be fine) – Aktau Nov 16 '11 at 11:42
  • Quartz runs fine on tomcat, jetty, jboss etc. I don't know about Scalatra but I'm sure it's possible since this is Java. – cherouvim Nov 16 '11 at 12:52