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

Discussion in 'Java' started by davout, May 13, 2005.

  1. davout

    davout Guest

    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?
    davout, May 13, 2005
    #1
    1. Advertising

  2. davout

    Juha Laiho Guest

    "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.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, May 13, 2005
    #2
    1. Advertising

  3. davout

    davout Guest

    Could you explain the JNDI idea a little further?

    "Juha Laiho" <> wrote in message
    news:d62tka$8j3$-int...
    > "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.
    > --
    > Wolf a.k.a. Juha Laiho Espoo, Finland
    > (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    > PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    > "...cancel my subscription to the resurrection!" (Jim Morrison)
    davout, May 13, 2005
    #3
  4. davout

    Juha Laiho Guest

    "davout" <> said:
    >"Juha Laiho" <> wrote in message
    >news:d62tka$8j3$-int...
    >> "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.

    >
    >Could you explain the JNDI idea a little further?


    Please start with Tomcat documentation on the topic:
    http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

    The text is somewhat biased towards database connectivity, but that
    is far from the only use of this functionality. Beginning of the
    page deals mostly with using JNDI resources, but towards the end
    there are examples of creating custom JNDI resources.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, May 14, 2005
    #4
  5. davout

    davout Guest

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


    "Juha Laiho" <> wrote in message
    news:d64f5q$hri$-int...
    > "davout" <> said:
    >>"Juha Laiho" <> wrote in message
    >>news:d62tka$8j3$-int...
    >>> "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.

    >>
    >>Could you explain the JNDI idea a little further?

    >
    > Please start with Tomcat documentation on the topic:
    > http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
    >
    > The text is somewhat biased towards database connectivity, but that
    > is far from the only use of this functionality. Beginning of the
    > page deals mostly with using JNDI resources, but towards the end
    > there are examples of creating custom JNDI resources.
    > --
    > Wolf a.k.a. Juha Laiho Espoo, Finland
    > (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    > PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    > "...cancel my subscription to the resurrection!" (Jim Morrison)
    davout, May 14, 2005
    #5
  6. davout

    Juha Laiho Guest

    "davout" <> said:
    >"Juha Laiho" <> wrote in message
    >news:d64f5q$hri$-int...
    >> "davout" <> said:
    >>>"Juha Laiho" <> wrote in message
    >>>news:d62tka$8j3$-int...
    >>>> "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.
    >>>
    >>>Could you explain the JNDI idea a little further?

    >>
    >> Please start with Tomcat documentation on the topic:
    >> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
    >>
    >> The text is somewhat biased towards database connectivity, but that
    >> is far from the only use of this functionality. Beginning of the
    >> page deals mostly with using JNDI resources, but towards the end
    >> there are examples of creating custom JNDI resources.

    >
    >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.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, May 16, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    799
  2. Replies:
    3
    Views:
    297
    noone
    Nov 9, 2006
  3. Christopher Brewster
    Replies:
    5
    Views:
    339
    John Machin
    Nov 14, 2008
  4. bluebaron
    Replies:
    3
    Views:
    735
    Jonathan N. Little
    Nov 4, 2009
  5. Guest
    Replies:
    2
    Views:
    177
    Foo Man Chew
    Dec 29, 2003
Loading...

Share This Page