users@grizzly.java.net

best practices on mixing sync code with grizzly

From: Paulo Lopes <paulo_at_mlopes.net>
Date: Fri, 9 Jan 2015 21:45:05 +0100 (CET)

Hello,

I am very new to grizzly, I am still reading the documentation and I am not sure
if I understand it correctly. I understand that I can mix synchronous code
within a http handler but is that a good practice?

For example, I've a simple http server where at a given path should make a jdbc
call to a database and return some data.

HTTP GET /logs -> jdbc call "select * from logs" -> return csv to client

Now in the http handler i can do this as:

req, res -> {
  // get db conn
  // prepare statement
  // execute sql
  // return data
}

Now my question is what should be the "best approach"?

* just do it like that?
* or have say a threadpool which would do that work and for each request,
suspend the response, delegate to a threadpool worker, resume the response and
write the result?

My idea is to keep this server as simple as possible, so I would like to just
use the http handler and avoid the servlet addon.

Again I've no experience with grizzly so any feedback would be appreciated :)

Thanks!
Paulo