Tomcat 5 - force different web apps to same instance of class?!?

D

davout

I have three different web apps running on a JBoss 4.x/Tomcat 5 deployment.

They all make use of a particular Java class that when first instantiated
extracts some data from a remote source. This extract takes some
considerable time.

Is there a way of having all three web apps share the same instance of this
class so that only the first activated web app incurs the delay?
 
J

Juha Laiho

davout said:
I have three different web apps running on a JBoss 4.x/Tomcat 5 deployment.

They all make use of a particular Java class that when first instantiated
extracts some data from a remote source. This extract takes some
considerable time.

Is there a way of having all three web apps share the same instance of this
class so that only the first activated web app incurs the delay?

You could perhaps present this class as a JNDI-accessible data source,
thus move it outside the applications, to be a part of the container
logic.

Alternatively, separate this functionality into another webapp, and have
other webapps call services on this separated webapp.
 
D

davout

I saw that somewhere else - but does that method create singleton instances
or what? Otherwise its no solution.
 
J

Juha Laiho

davout said:
I saw that somewhere else - but does that method create singleton instances
or what? Otherwise its no solution.

At least as far as I understand, Tomcat will create only one instance of
your JNDI provider class (per resource definition). Then, it's up to the
provider class to decide how many instances of the actual service class(es)
are created. Your application code will then first acquire a reference
to the provider class, and ask the provider class to give a reference to
an actual service class instance.

Note that if you create only one instance of the service class, the
service class must be prepared to work in a multithreaded environment
(but I guess in your case this is not a problem).

If the service class is something that was not threadsafe (such as a JDBC
database connection class), the solution would be to use a pooling class
to coordinate access to a set of these service classes, giving a reference
to any given instance to only one client at a time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top