You should be able to access the classes of the application directly from your
servlet code, as long as they're being loaded from the classpath into the same
JVM.  The simplest approach is to just provide whatever hooks you want as static
methods in the application's main class (or as instance methods, with a static
call to get the instance), then call them directly from the servlet.

Alternatively, you can decouple the two by providing an intermediary.  Define an
interface for the calls you want to use, along with a separate class which has
methods allowing it to be passed an instance of the interface and to return the
instance.  Your application implements the interface, and registers itself with
the intermediary class at startup.  The servlet uses the call to the
intermediary class to get the interface instance reference, then calls the
application's implementation of the interface directly.  This only requires the
interface and the intermediary class to be shared between the application and
the servlet.

  - Dennis

Dennis M. Sosnoski
Sosnoski Software Solutions, Inc.
http://www.sosnoski.com

Theodore Tegos wrote:
>
> Hi,
>     I have a Java application which will run on the background as a daemon
> and perform some kind of operation. I also have a servlet and I want the
> information from the application to be available to it. Do you have any
> suggestions about the way that the application and the servlet could
> communicate? I know that two servlets can communicate by using their
> "servlet context" but what about an application and a servlet?. Since the
> application and the servlet will run on the same JVM, the communication
> should preferably be done directly by using memory. This means that URL
> connections or sockets are not a good solution and neither is the use of
> files to exchange the information.  Is there any other way that the
> communication could be established efficiently?
> Thanks in advance,
>
> Theodore.
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to