servlet/database: how to do fine-grained database connection and statement management (not bound to servlet lifetime)

StackOverflow https://stackoverflow.com/questions/8133391

Domanda

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?

È stato utile?

Soluzione

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).
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top