This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Running as one process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Running as one process" Watch "Running as one process" New topic
Author

Running as one process

Eli Hodos
Greenhorn

Joined: Jan 26, 2011
Posts: 4

Hi all,
Currently I have a Tomcat server with a servlet that when called communicates with a java application through RMI.
I need to embed the java application into Tomcat so that I can directly make calls from the servlet to objects without the need for RMI.
The Java application should be run once when Tomcat starts.
Can I do this and how ?
Many thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

Welcome to the JavaRanch, Eli!

The standard JVM only supports a single Application running within its environment, and since Tomcat itself is an Application, that kind of rules out what you seem to want. If you just want application functions within Tomcat, however, that can be done, as long as you're careful where you put things and don't do things that interfere with Tomcat's own operation. Alternatively, you can also flip things inside out and have your application run an embedded Tomcat server.

RMI is about as efficient as it gets when you have two systems running in 2 separate address spaces (VMs). Keeping separate address spaces is a good way to reduce the coupling between major systems, so it's not something that should be discarded lightly.


Customer surveys are for companies who didn't pay proper attention to begin with.
Eli Hodos
Greenhorn

Joined: Jan 26, 2011
Posts: 4

Hi Tim,

Thank you for your comment.

While my application is working as two separate processes communicating with RMI it has some withdraws.
The main problem is that if Tomcat communicates with my app using RMI it opens its own session and as my app needs to distinguish among original sessions (user's ) it has a problem as all appear to come from the same user (tomcat).
I had successfully combined the two to run as one and I was debating how to communicate between them.
It seems that embedding tomcat inside my app will be a better approach then calling my app from tomcat, specially if i do it now from the servlet which doesn't seem as the right thing to do as it needs to be called once when tomcat starts.
Still all this is very confusing because my app relies now on communication through a dedicated port on which its listening to meaning a session is required so If the user communicates with the embedded tomcat on port 8080 I will still need to communicate from tomcat with my app at the dedicated port ... and I end at the same spot.

It will help if you could suggest a way to call my Start java class once from Tomcat at startup, not from the servlet.

Thanks,
Eli
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

Usually when you do this kind of stuff where one RMI server has to discriminate among multiple clients, you include some sort of session ID token as one of the RMI parameters,
Eli Hodos
Greenhorn

Joined: Jan 26, 2011
Posts: 4

Yes Tim, currently I can distinguish among sessions using a parameter sent in the request but the system currently works at the session level and we wanted to avoid changing that by placing filters selecting information for each "real" session as it slows the system down.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

I'm not sure I understood that. What I'd expect would be that for each requesting web user (HttpSession), you'd generate a corresponding RMI session ID and use that to manage that user's interactions with the RMI server. So that each user's interactions would be distinct from the other user interactions.
Eli Hodos
Greenhorn

Joined: Jan 26, 2011
Posts: 4

Tomcat is an intermediate web server receiving information from a customer's site on port 8080 and sending it to my app which listens on a dedicated port.
My app sends a reply to Tomcat which replies to the customer's site.
Therefore the session I care for is the one connecting the customer web site with Tomcat but the session that my app sees is the session between Tomcat and the app on a dedicated port and the original session between the customer's web site and Tomcat is passed as a parameter.
I would like if possible that my app (maybe with an embedded tomcat server ?) could handle both 8080 and dedicated port calls centralized and pass data internally without creating a new session.
Port 8080 is just the default .. i can change that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running as one process