Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: Performance issue

Leon Rosenberg

2007-01-02

Replies:

u welcome :-)
L

On 1/2/07, Daniel Chacón Sánchez <danielccss@(protected):
> Thanks Leon!!!, I got it!!!
>
> 2007/1/2, Leon Rosenberg <rosenberg.leon@(protected)>:
> >
> > On 1/2/07, Daniel Chacón Sánchez <danielccss@(protected):
> > > Thanks
> > >
> > > Leon, about using the servlet context, I read that on a distributed
> > > application the share information of the servlet context is not
> > entererly
> > > global right?:
> >
> > Right, but since the data is readonly its ok to have a copy per
> > webserver, right? It doesn't harm you to put one data-object (even a
> > complex one) in the application scope. If you need to check for
> > updates periodically you could make use of the subject-observer
> > pattern and notify the webservers from the business layer via
> > rmi/corba/jms/whatever to renew their data or just check if the data
> > is still valid and replace it if needed periodically in a separate
> > daemon thread.
> >
> > >
> > > *"...In the case of a web application marked "distributed" in its
> > deployment
> > > descriptor, there will be one context instance for each virtual machine.
> > In
> > > this situation, the context cannot be used as a location to share global
> > > information (because the information won't be truly global). Use an
> > external
> > > resource like a database instead."*
> > >
> > >
> > > About the second solution that you gave to me, I do not understand, you
> > said
> > > that for example in my BaseAction Class create a method to put the
> > objects
> > > in the request? The problem is that in every request the application
> > will go
> > > to the database to load the objects and then put them on the request!
> > What I
> > > do not understand is how to put the objects in the request without have
> > to
> > > go the database each time that a request is made and the method in the
> > > BaseAction is call.
> >
> > BaseAction extends Action{
> >  private static Data1Class data1;
> >  private static Data2Class data2;
> >  ....
> >
> >  static{
> >    data1 = createData1FromDB();
> >    data2 = createData2FromDB();
> >  }
> >
> >  //now in my actions i have my own execute method, you may have
> > something //similar:
> >      protected void preProcessExecute(
> >                 ActionMapping mapping,
> >                 ActionForm af,
> >                 HttpServletRequest req,
> >                 HttpServletResponse res)
> >                 throws Exception{
> >
> >           req.setAttribute("data1", data1);
> >           req.setAttribute("data2", data2);
> >          .........
> >     }
> >
> >      protected void postProcessExecute(
> >                 ActionMapping mapping,
> >                 ActionForm af,
> >                 HttpServletRequest req,
> >                 HttpServletResponse res)
> >                 throws Exception{
> >
> >      }
> >
> >      public abstract ActionForward myExecute(
> >           ActionMapping mapping,
> >           ActionForm af,
> >           HttpServletRequest req,
> >           HttpServletResponse res)
> >           throws Exception;
> >
> >
> >      public final ActionForward execute(
> >           ActionMapping mapping,
> >           ActionForm bean,
> >           HttpServletRequest req,
> >           HttpServletResponse res)
> >           throws Exception {
> >
> >
> >           preProcessExecute(mapping, bean, req, res);
> >           ActionForward forward = myExecute(mapping, bean, req,
> > res);
> >           postProcessExecute(mapping, bean, req, res);
> >           return forward;
> >      }
> > }
> >
> > You just have to ensure, that when an Action overwrites preProcess it
> > calls super.preProcess.
> > The advantage of this method is, that actions at the end of the
> > hierarchy have a chance to overwrite the data by the base action,
> > which is quite useful for internationalization and such.
> >
> > Same rules for updates as for servletContext apply.
> >
> > regards
> > Leon
> >
> >
> > >
> > > 2007/1/2, Leon Rosenberg <rosenberg.leon@(protected)>:
> > > >
> > > > The easiest way is to initialize the data once in the
> > > > init(ServletConfig) method of the servlet and put them into the
> > > > application scope (servletcontext). The struts tags will be able to
> > > > access the data directly, so you don't need to change a bit.
> > > > Of course the data structures theirself must be threadsafe to access,
> > > > which shouldn't be a problem if you are only reading them.
> > > >
> > > > Alternatively you can perform this in a static initializer in a action
> > > > and put them in the request scope of each request (if you have a
> > > > common code block all actions are passing through, like authorization)
> > > > or into the application scope on first request (which would need a bit
> > > > of synchronization with double checked locking)
> > > >
> > > > regards
> > > > leon
> > > >
> > > > On 1/2/07, Daniel Chacón Sánchez <danielccss@(protected):
> > > > > Hi all, I'm using struts framework on my application, but I have a
> > > > > perfomance question.
> > > > >
> > > > > When my application starts I load objects in session that may or may
> > not
> > > > > will be used (depends on what the user does), for example I load
> > the
> > > > health
> > > > > centers, hospitals, countries, etc, that will be available for the
> > users
> > > > in
> > > > > html:selects, I know that to had many objects in session is not
> > good, in
> > > > > fact each time the user click on one application option (menu) all
> > the
> > > > > objects in session are erased, except the ones that I load on the
> > start
> > > > of
> > > > > the application. Is there a way (maybe a pattern) to load this
> > objects
> > > > in
> > > > > the moment that are needed, and not load all at the start of the
> > > > > application. This object are use on differents modules so I load
> > them on
> > > > the
> > > > > start of the aplication and put them in sesion for not to go to the
> > > > database
> > > > > each time I need to load them on a html:select.
> > > > >
> > > > > any solution, idea? or that is the only way?
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > > > For additional commands, e-mail: user-help@(protected)
> > > >
> > > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.