webtier@glassfish.java.net

Glassfish, JSPs and Java classes. How static is static?

From: <webtier_at_javadesktop.org>
Date: Mon, 27 Jul 2009 04:18:30 PDT

I've been playing with Glassfish recently and getting to know Java a bit better. I've been building a fairly simple website and had some questions.

So, my model is this: I've got some JSPs (tier 1, effectively). These then call methods within classes in various classes / packages (tier 2). The database conneciton (tier 3) is created in the glassfish admin console as a JDBC resource - when one of the methods needs to access the db, it calls this:

[code]
public class DataConnection {
    public static DataSource getDevdb() throws NamingException {
        Context c = new InitialContext();
        return (DataSource) c.lookup("java:comp/env/devdb");
    }
}
[/code]

 It's not clear to me whether the methods in the tier 2 classes should be static or not. All they're doing is getting some data out of the database based on parameters given to them, chucking it in an object and returning it to the JSP, which then formats the output. Within the context of the application server, how static is a static variable? Is there one per request? Per thread? One for the entire server instance? If the tier 2 methods are static, will an executing request block all further requests until that method is complete?

Thanks
[Message sent by forum member 'growse' (growse)]

http://forums.java.net/jive/thread.jspa?messageID=357660