singleton serialization and weblogic - help!

L

Lincoln Marr

hi everyone,

I'm trying to serialize a singleton cache object we're using for our
website running on weblogic 6.1. I've made sure the singleton class
implements serializable, and i've also put the following method in the
singleton class (ChartCache.java):

private Object readResolve()
{
return theInstance; //which is of type ChartCache
}

By the way I'm using jdk 1.3.

Basically I've written a jsp to get the current instance of the cache
and serialize it to a file. When I invoke another jsp i want it to
reinflate the object and place it back into the weblogic jvm so it can
once again be accessed as a singleton by all classes in the webapp. At
the moment its just not working - the cache object will eventually
take over half an hour to create (huge database processing going on)
so I want the option, if weblogic falls over, to reinstantiate the
cache without having to rebuild it from scratch. The cache will only
be refreshed once a day.

I'll c&p my jsp code below...

======================= restoreCache.jsp

<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%

ChartCache theCache = null;
try
{
String filename = "chartCache.dat";
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fis);
theCache = (ChartCache)in.readObject();
in.close();
}
catch(Exception e)
{
Logger.log(e);
}
%>

Resurrected chart cache from file.


======================= saveCache.jsp

<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%
ChartCache theCache = ChartCache.getInstance();
String fileName = "chartCache.dat";
try
{
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(theCache);
oos.flush();
oos.close();
}
catch(Exception e)
{
Logger.log(e);
}
%>


Wrote cache object to file.

============================

At the moment, a file is getting written but it seems suspiciously
small (73 bytes!) for what is a very large object. When I try to load
it up again, I get no errors but when I call ChartCache.getInstance()
(my singleton) it recreates the cache rather than using the one I've
reinflated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,194
Latest member
KarriWhitt

Latest Threads

Top