Running 2 webapp in Tomcat - 1 or 2 JVMs

Discussion in 'Java' started by James Yong, Nov 28, 2005.

  1. James Yong

    James Yong Guest

    Hi,

    If I run 2 web applications in a Tomcat, is that 2 web application run by 2
    JVMs or 1 JVM?

    Regards,
    James
    James Yong, Nov 28, 2005
    #1
    1. Advertising

  2. James Yong

    Guest

    Hello
    1 JVM.I suppose it is virtual
    , Nov 28, 2005
    #2
    1. Advertising

  3. James Yong

    Guest

    Hello
    1 JVM.I suppose it is virtual
    , Nov 28, 2005
    #3
  4. James Yong

    Roedy Green Guest

    On Mon, 28 Nov 2005 23:27:32 +0800, "James Yong" <james$@i$.com>
    wrote, quoted or indirectly quoted someone who said :

    >If I run 2 web applications in a Tomcat, is that 2 web application run by 2
    >JVMs or 1 JVM?


    One.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 28, 2005
    #4
  5. James Yong

    James Yong Guest

    <> wrote in message
    news:...
    > Hello
    > 1 JVM.I suppose it is virtual
    >


    Thanks.

    Does that means that it is impossible to implement RMI between them, since
    RMI requires at least 2 JVM to work?

    Regards,
    James
    James Yong, Nov 28, 2005
    #5
  6. James Yong

    Guest

    i believe, if you are under 1 jvm you would be able to share objects
    between the two contexts.

    things to try (in any order of preference)
    1) you might have to write a patch and alter tomcat to add a hook into
    the bootstrap to do this "under the table"..

    2) the more appropriate way would be to do it "above the table", and
    have a servlet to servlet communication through a post/get... assuming
    the table is conceptually at the context level.

    3) another possibility i just thought of, is to do this via jndi.
    that's kinda the purpose of it. and probably the best solution.

    4) run two seperate jvm's and then rmi would make more sense.

    www.binaryfrost.com
    , Nov 28, 2005
    #6
  7. James Yong

    Roedy Green Guest

    On Tue, 29 Nov 2005 01:57:55 +0800, "James Yong" <james1@$1.com>
    wrote, quoted or indirectly quoted someone who said :

    >Does that means that it is impossible to implement RMI between them, since
    >RMI requires at least 2 JVM to work?


    the R in RMI stands for Remote. It jumps through hoops because sender
    and receiver are in different JVMS. When they are in the same JVM you
    can simply and efficiently past references back and forth.

    Typically, RMI involves at least three JVMs, a RMI server, an RMI
    application server and a client.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 29, 2005
    #7
  8. James Yong

    Roedy Green Guest

    On 28 Nov 2005 10:18:57 -0800, wrote,
    quoted or indirectly quoted someone who said :

    >1) you might have to write a patch and alter tomcat to add a hook into
    >the bootstrap to do this "under the table"..


    a garden variety static class will let anyone communicate with anyone
    in a JVM.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 29, 2005
    #8
  9. James Yong

    Roedy Green Guest

    On Tue, 29 Nov 2005 02:37:28 GMT, Roedy Green
    <> wrote, quoted or
    indirectly quoted someone who said :

    >a garden variety static class will let anyone communicate with anyone
    >in a JVM.


    More precisely the static variables of a garden variety class will let
    anyone communicate with anyone within a JVM.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 29, 2005
    #9
  10. James Yong wrote:
    > <> wrote in message
    > news:...
    >
    >>Hello
    >>1 JVM.I suppose it is virtual
    >>

    >
    >
    > Thanks.
    >
    > Does that means that it is impossible to implement RMI between them, since
    > RMI requires at least 2 JVM to work?


    It probably does mean that you cannot do RMI between the two apps, but
    I'm not certain of it. A better question for you to think about,
    however, is whether it makes sense to split things up into two web
    applications in the first place when they are tightly enough bound
    together that you /want/ to do RMI between them.


    --
    John Bollinger
    John C. Bollinger, Nov 29, 2005
    #10
  11. James Yong

    Guest

    > More precisely the static variables of a garden variety class will let
    > anyone communicate with anyone within a JVM.

    Depends ... if the different web applications are loaded via different
    class loaders then statics do not work.

    Also, RMI has its use also in a VM. Using RMI makes sure that you do
    not share any member between apps, really important if you want to
    unload apps dynamically, like OSGi.

    Kind regards,

    Peter Kriens
    OSGi Evangelist

    Roedy Green wrote:
    > On Tue, 29 Nov 2005 02:37:28 GMT, Roedy Green
    > <> wrote, quoted or
    > indirectly quoted someone who said :
    >
    > >a garden variety static class will let anyone communicate with anyone
    > >in a JVM.

    >
    > More precisely the static variables of a garden variety class will let
    > anyone communicate with anyone within a JVM.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Java custom programming, consulting and coaching.
    , Nov 29, 2005
    #11
  12. James Yong

    James Yong Guest

    >
    > It probably does mean that you cannot do RMI between the two apps, but
    > I'm not certain of it. A better question for you to think about,
    > however, is whether it makes sense to split things up into two web
    > applications in the first place when they are tightly enough bound
    > together that you /want/ to do RMI between them.
    >
    >
    > --
    > John Bollinger
    >


    Hi John,

    The 2 web application serves different purposes but web app A requires some
    information from web app B.
    So for my case, it make sense to split them, and to communicate via RMI.

    However I also forsee a possibility that they may be hosted in the same
    container. Hence my questions in this threads.

    I will probably code some functions to allow switching of RMI with an
    alternative solution that is recomended in this thread.

    Regards,
    James
    James Yong, Nov 29, 2005
    #12
  13. James Yong

    James Yong Guest

    "Roedy Green" <> wrote in
    message news:...
    > On Tue, 29 Nov 2005 02:37:28 GMT, Roedy Green
    > <> wrote, quoted or
    > indirectly quoted someone who said :
    >
    > >a garden variety static class will let anyone communicate with anyone
    > >in a JVM.

    >
    > More precisely the static variables of a garden variety class will let
    > anyone communicate with anyone within a JVM.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Java custom programming, consulting and coaching.


    Hi Roedy,

    I am not sure how a static class can help web app A calling and getting
    results from web ap B. Can you give an example?

    Regards,
    James
    James Yong, Nov 29, 2005
    #13
  14. James Yong

    James Yong Guest

    <> wrote in message
    news:...
    > i believe, if you are under 1 jvm you would be able to share objects
    > between the two contexts.
    >
    > things to try (in any order of preference)
    > 1) you might have to write a patch and alter tomcat to add a hook into
    > the bootstrap to do this "under the table"..
    >
    > 2) the more appropriate way would be to do it "above the table", and
    > have a servlet to servlet communication through a post/get... assuming
    > the table is conceptually at the context level.
    >
    > 3) another possibility i just thought of, is to do this via jndi.
    > that's kinda the purpose of it. and probably the best solution.
    >
    > 4) run two seperate jvm's and then rmi would make more sense.
    >
    > www.binaryfrost.com
    >


    Hi cbroussard,

    Your recommendation is very valuable. I will start to look into the jndi
    solution.

    Regards,
    James
    James Yong, Nov 29, 2005
    #14
  15. James Yong

    Roedy Green Guest

    On Tue, 29 Nov 2005 22:03:35 +0800, "James Yong" <james1@$1.com>
    wrote, quoted or indirectly quoted someone who said :

    >I am not sure how a static class can help web app A calling and getting
    >results from web ap B. Can you give an example?


    In a very simple example:

    public class Common
    {
    public static string share;
    }


    A has code like this:

    Common.share = "I will meet you at the casbah";

    B has code like this:

    if ( Common.share != null ) ...

    In a real example A and B could call methods of Common and Common
    would call methods in the concurrent package. See
    http://mindprod.com/jgloss/queue.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 29, 2005
    #15
  16. James Yong

    James Yong Guest

    "Roedy Green" <> wrote in
    message news:...
    > On Tue, 29 Nov 2005 22:03:35 +0800, "James Yong" <james1@$1.com>
    > wrote, quoted or indirectly quoted someone who said :
    >
    > >I am not sure how a static class can help web app A calling and getting
    > >results from web ap B. Can you give an example?

    >
    > In a very simple example:
    >
    > public class Common
    > {
    > public static string share;
    > }
    >
    >
    > A has code like this:
    >
    > Common.share = "I will meet you at the casbah";
    >
    > B has code like this:
    >
    > if ( Common.share != null ) ...
    >
    > In a real example A and B could call methods of Common and Common
    > would call methods in the concurrent package. See
    > http://mindprod.com/jgloss/queue.html
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Java custom programming, consulting and coaching.


    Hi Roedy,

    Thanks for the explanation

    Regards,
    James
    James Yong, Nov 30, 2005
    #16
  17. James Yong wrote:
    >>It probably does mean that you cannot do RMI between the two apps, but
    >>I'm not certain of it. A better question for you to think about,
    >>however, is whether it makes sense to split things up into two web
    >>applications in the first place when they are tightly enough bound
    >>together that you /want/ to do RMI between them.
    >>
    >>
    >>--
    >>John Bollinger
    >>

    >
    >
    > Hi John,
    >
    > The 2 web application serves different purposes but web app A requires some
    > information from web app B.
    > So for my case, it make sense to split them, and to communicate via RMI.
    >
    > However I also forsee a possibility that they may be hosted in the same
    > container. Hence my questions in this threads.
    >
    > I will probably code some functions to allow switching of RMI with an
    > alternative solution that is recomended in this thread.


    I personally would prefer a solution that works all the time. I see two
    alternatives that look reasonable:

    1) App A obtains the needed information from app B through appropriate
    methods on B's web interface. If you like buzz words, you could
    describe this as B providing a web service that A uses. This approach
    makes sense if providing the required information falls in, or close to,
    B's general area of operation.

    2) App A and app B share a common back end with which they both
    communicate, but which is logically separate from either. They don't
    communicate directly. The back end might be as simple as a common
    database, or as complex as a full-blown J2EE application comprising one
    or more EJBs, etc. A simpler RMI-based back end would fall in the
    middle, and there are other alternatives as well.

    I don't particularly care for the idea of B providing a back-door
    interface for A to use to get a hold of information that B just happens
    to be holding (though it's not clear whether that's what you were asking
    about).

    --
    John Bollinger
    John C. Bollinger, Dec 1, 2005
    #17
  18. James Yong

    James Yong Guest

    "John C. Bollinger" <> wrote in message
    news:dmllfk$236$...
    >
    > I personally would prefer a solution that works all the time. I see two
    > alternatives that look reasonable:
    >
    > 1) App A obtains the needed information from app B through appropriate
    > methods on B's web interface. If you like buzz words, you could
    > describe this as B providing a web service that A uses. This approach
    > makes sense if providing the required information falls in, or close to,
    > B's general area of operation.
    >
    > 2) App A and app B share a common back end with which they both
    > communicate, but which is logically separate from either. They don't
    > communicate directly. The back end might be as simple as a common
    > database, or as complex as a full-blown J2EE application comprising one
    > or more EJBs, etc. A simpler RMI-based back end would fall in the
    > middle, and there are other alternatives as well.
    >
    > I don't particularly care for the idea of B providing a back-door
    > interface for A to use to get a hold of information that B just happens
    > to be holding (though it's not clear whether that's what you were asking
    > about).
    >
    > --
    > John Bollinger
    >


    Hi John,

    I think I like solution A better. Thanks for the advice. I have been trying
    to look for information about doing a custom JDNI solution, but couldn't get
    the revelant information. So I will go back and look at XML solutions

    Regards,
    James
    James Yong, Dec 1, 2005
    #18
  19. Why not use something like SOAP or XML-RPC? That way it work the same on one JVM, two JVMs or remotely on a completely different
    server.

    James Yong wrote:
    > <> wrote in message
    > news:...
    >
    >>Hello
    >>1 JVM.I suppose it is virtual
    >>

    >
    >
    > Thanks.
    >
    > Does that means that it is impossible to implement RMI between them, since
    > RMI requires at least 2 JVM to work?
    >
    > Regards,
    > James
    >
    >
    Dennis Willson, Dec 2, 2005
    #19
    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:
    6
    Views:
    413
    S. Justin Gengo [MCP]
    Feb 10, 2006
  2. Replies:
    1
    Views:
    1,244
    Chris Uppal
    Jan 5, 2005
  3. Sean Berry
    Replies:
    3
    Views:
    4,541
    Tim Terry
    Dec 19, 2005
  4. Replies:
    0
    Views:
    364
  5. Andrew
    Replies:
    7
    Views:
    404
    Andrew
    Jun 28, 2009
Loading...

Share This Page