I have a web application (written primarily using Struts) that allows long database queries (and other processes that could take a while to complete) to run as background Threads. While these processes are running, a user may view the status page of these "Jobs", which auto-refreshes itself every so often, or the user can check the status of it later by selecting it from a list of jobs. Currently, these "Job" Threads are passed an action specific bean that it populates with it's job specific data and this bean remains in memory until the user actually views the page that displays the data that was populated during one of these jobs. The obvious problems with this approach are that: 1) If anything goes wrong with the application or server and something needs to be restarted, the user won't see the result of the job they created since it'll no longer reside in memory 2) The user can only view the Job X amount of times before it is removed from memory and having too many possible viewings for jobs can quickly eat up memory resources. I have decided that Serializing these beans so that they may be written to the file system is a reasonable solution so that they may be viewed as many times as possible and persist after any sort or re-starts (assuming the jobs complete themselves before any such events occur). The problem I'm faced with however, is that there can be many different types of beans that are serialized. The only easy solution I've though of for solving this is to store what type of bean it was somewhere, grab that info when I load the Object from file, and cast it as that type before handing it off to display components. The reason I don't like this solution is because it creates messy code and requires someone to add new bean type tests to the code every time a new type of job is created. Does anyone have a better solution to this problem?
Joined: Feb 10, 2001
Hi Alex, Try out following thing, Define an interface which will have all ur getter methods. Then make all ur beans implement this interface. In this case you are not required to remember type of all beans when you load object from file ,as every bean will be of ur Interface type. hope this helps Cheers Praful [ February 11, 2004: Message edited by: Praful Thakare ]
All desirable things in life are either illegal, banned, expensive or married to someone else !!!