You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chris Campbell <ch...@lincmedia.co.jp> on 2002/05/07 09:52:54 UTC

RE: Problem: JSP calls singleton. Singleton's data changes, but J SP s till shows old data from that singleton

Assuming the browser is not just giving you a cached page, in the servlet,
if you log the contents of _instance just before return _instance; do you
see the new data?

ChrisC

> -----Original Message-----
> From: "Pykalainen, Eero" [mailto:Eero.Pykalainen@yomi.com]
> Sent: Tuesday, April 23, 2002 8:34 PM
> To: 'tomcat-user@jakarta.apache.org'
> Subject: Problem: JSP calls singleton. Singleton's data 
> changes, but JSP s till shows old data from that singleton
> 
> 
> I am using Tomcat 4.0.4-b1 (and Struts 1.0.2) on W2K.
> 
> I have a singleton class that keeps data inside of it.
> 
> I have a JSP page that calls the singleton.
> 
> When singleton's data is up-to-date, JSP page opens quickly. 
> When it isn't,
> singleton updates its data structure from database and then 
> JSP shows up.
> There is only one problem: although singleton updates itself, 
> singleton's
> changed data isn't visible in the JSP page. It still shows old data.
> 
> JSP:
> 
> <%
>   ListOfAllComponents listOfAllComponents =
> ListOfAllComponents.getInstance();
>   // extracting data here...
> %>
> 
> Singeton class' getInstance() method:
> 
> public static synchronized ListOfAllComponents getInstance() {
>   try {
>     if ( _instance == null ) {
>       _instance = new ListOfAllComponents();
>     }
> 
>     if ( upToDate == false ) {
>       _instance.getListOfAllComponents();
>       _instance.log("Refreshed listOfAllComponents");
>       upToDate = true;
>     }
>   } catch ( Throwable e ) {
>       e.printStackTrace( System.out );
>   }
> 
>   return _instance; 
> }
> 
> I call my log method inside the getListOfAllComponents() 
> method so I *know*
> that the data is changed.
> 
> My workflow:
> 
> 1) I call the JSP page that shows data from singleton
> 2) I call another JSP page that changes the upToDate boolean flag
> 3) I call the JSP page that shows data from singleton. At 
> this phase the log
> method inside getListOfAllComponents method logs the 
> *updated* data to my
> log file
> 4) JSP page shows up. It still shows the old data.
> 
> Am I doing something wrong or missing something here?
> 
> Thank you very much of your help, 
>                                   Eero
> 
> 
> -- 
> Eero Pykalainen, Software Developer, Yomi Solutions Ltd.
> 
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>