Java
--
Questions
--
Followers
Top Experts
Anyway, what I thought would happen is that as the applications make calls to DatabasePoolFactory.getIns
package BslDatabasePool;
import java.util.*;
import SPAR.BslException.*;
public class BslDatabasePoolFactory
{
static private Hashtable dbList = null;
/**
* Retrieves an instance of the named PoolManager. This should be used when you
* want to connect to a pool which you know ( or hope! )to be available, and you don't want to
* go to the trouble of having to define the db context. If the Pool is actually
* NOT running, then an UnknownPoolException is thrown.
*/
static public synchronized PoolManager getInstance(String PoolName) throws Exception
{
return getInstance(PoolName,(Spar
}
/**
* Retrieves an instance of the named PoolManager, creating a new one with
* the supplied name and database context if one does not already exist. If
* a pool manager exists with the specified name, YOU WILL BE RETURNED A
* REFERENCE TO IT REGARDLESS OF WHETHER OR NOT ITS CONTEXT MATCHES THAT
* WHICH YOU PASSED IN. This means that there is a possibility that you
* may end up connecting to a database that you don't want to. Making sure
* that this doesn't happen is dependent upon sensible naming standards.
*/
static public synchronized PoolManager getInstance(String PoolName,
SparDatabaseContext SdbC)
throws Exception,
UnknownPool
{
if (dbList == null)
{
System.out.println("Creati
dbList = new Hashtable();
}
PoolManager tmp = (PoolManager)dbList.get(Po
if (tmp == null)
{
System.out.println("PoolMa
if (SdbC == null)
{
throw(new UnknownPool(PoolName));
}
tmp = new PoolManager(SdbC);
tmp.setName(PoolName);
dbList.put(PoolName,tmp);
}
else {System.out.println("Pool Already Available");};
return tmp;
}
}
My understanding of static ( which I'm sure is wrong! ) is such that, as the first call on the static getInstance method is received, a dbList hashtable will be created and the message "Creating New Database Factory" will be produced. After that, any subsequent calls to getInstance will go to the hashtable and retrieve the specified poolmanager object. This appears to happen as long as only one tomcat servlet is running. When a second servlet calls getInstance, I would expect it to see that the static hashtable dbList is already in existence and just put any new pool manager instances in to the same hashtable. What _actually_ happens is that I see another "Creating New Database Factory" message, which I guess means that a new hash table is being created and populated.
My understanding was that a static class would exist once in the JVM. This doesn't appear to be happening. Where is my understanding letting me down?
Dave
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
1. If you're going to use some kind of pool manager, you could arrange for it to be preloaded by the context.
2. If you're going to do that, you may as well create dbList as soon as the class is loaded:
static private Hashtable dbList = new Hashtable();
3. Since this reference will never change, why not:
private static final Hashtable dbList = new Hashtable();
4. On an unrelated note, I would rename UnknownPool to UnknownPoolException.
Listening Curiously...
-K
I say if Tomcat will allow it as Tom might not allow private constructors.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
objects - given what you're saying about the separate class loader for each servlet, am I wasting my time in trying to produce a poolfactory which will serve up poolmanagers across a complete tomcat installation?
Dave

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Even that won't work as the paper girionis mentions explains, so my suggestion won't cure the problem. The problem can be treated by applying the principles the paper's author describes beginning 'Consequences'.
Thanks
Dave






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
http://access.adobe.com/perl/convertPDF.pl?url=http://www.javageeks.com/Papers/JavaStatics/JavaStatics.pdf
If that doesn't work, let me know and I'll mail you the file.
In the meantime you can save yourself some time by implementing the singleton anyway, as we were discussing, although as you'll see when you read the document, this will not be sufficient in itself to cure the problem.
Dave
Hope it helps.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
> which will serve up poolmanagers across a complete
> tomcat installation?
No, what you need to do is ensure your singleton pool factory is loaded by the system class loader. You can do this by ensuring the classes are found in the ext directory or the classpath.
I will leave a recommendation in the Cleanup topic area that this question is:
- points to girionis
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
girionis
Cleanup Volunteer
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.