• Post Reply Bookmark Topic Watch Topic
  • New Topic

Good way to cast unknown Serialized Object types?  RSS feed

 
Alex Cano
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!