The easiest approach is to retrieve all the content for later pages in the
Action for the first page. This would slow the first page, but would allow
later pages to be pulled from cache. This seems like the easiest approach.
It could be accomplished using a course-grained Entity Bean or some sort of
Data Access Object (DAO) stored in session.

If you really want to send the first page to the use while caching the
later pages "simultaneously", you'd have to have more than one thread
working on it.

This is because the Struts main controlling Servlet directs the View (i.e.
jsp file) to be rendered and sent to the use AFTER you return an
ActionForward.

In other words, you have to "return" from your Action class as a
prerequisite to sending the response to the user. There may be a way around
this that I'm not aware of.

There are still ways you could accomplish this if you really want to:

One method may be to have your Action class launch a seperate thread which
fetches the data and stores it in the form bean. You could store the form
bean in the session (or servlet) context and the thread should be able to
access it. I recommend against this approach though, once you have multiple
threads updating a single object you're asking for trouble.

A better approach may be this:

 - Create a startup servlet (outside Struts) that launches a thread in its
init() method to perform caching for you.
 - Put an object in the Servlet context that holds cache requests.
 - In the action class for the first page, add a "cache request" to the
object in the Servlet Context
 - Have the thread from the startup servlet monitor this object
periodically and perform the fetching of the data when it finds a new cache
request.
 - The startup thread then updates the "cache request" object with either
an object holding the cached data or the name of a ServletContext attibute
where the cached object is stored.

I'm not completely happy with this as it seems a bit of a hack - but it
should work and allows you to solve the problem using only a servlet
container (i.e. Tomcat only solution).


A better way (assuming you have an ejb container that supports JMS), would
be to have the first Action class send a JMS message requesting the data.
The next Action class could then receive via the JMS response an object
containing all the cached data. If there's no JMS response, it could just
go get the data itself. JMS Provides a good method of doing "asynchronous"
processing. And it's easier than most people think.

Good luck,

FWIW -
Kevin















"Chen, Dean (Zhun)" <[EMAIL PROTECTED]> on 05/03/2002 09:27:45 AM

Please respond to "Struts Users Mailing List"
      <[EMAIL PROTECTED]>

To:   "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
cc:    (bcc: Kevin Bedell/Systems/USHO/SunLife)
Subject:  Loading Database


Hi,

For struts, I know it's possible to load a bean and then display the
contents of the bean in sequence. Is it possible to load a bean partially,
display the contents, while simultaneously loading the rest of the bean.
This way when the user is viewing the 1st page, the rest of the pages are
loading. We are trying to make the system feel as responsive as possible.

Also, if there are any workarounds, I would really appreciate it.

Thanks,

Dean Chen

--
To unsubscribe, e-mail:   <
mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <
mailto:[EMAIL PROTECTED]>







---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure.  If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited.  If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to