Persisting Threaded Tasks in Web Applications with Hibernate?

M

Mike S

Hello,

I would like to accomplish something in a Struts web application that
I have not done before. I'd like some feedback on my approach and
suggestions to make it better or best implement it. The part of the
app that concerns me is one where a user initiates a process by
clicking on a link and ends it by clicking a different link at some
later time.

The only way I can think of to accomplish this is by extending Thread
on the class in question that is responsible for the process. Then
the Action that is to load the repeated process will instantiate the
class, put a reference to the object in the Session and call .start()
on it. That way the Action can finish what it needs to do, return an
ActionMapping and be done while the threaded process continues to run.
When the user then calls the termintating Action it will pull the
reference to the Thread out of the Sesion and call .setStop(true) on
it (my thread continues to run while the boolean I'm setting is false
or it times out).

This approach works, but it obviously has holes. Sure, I can put in
simple logic to make sure that only one instance of my thread runs at
a time by updating a flag in a database when the process
starts/finishes but what happens if a user starts myThread and then
closes his browser? He kills the session and prevents myThread from
being accessed again. This is why I am thinking that my only option
is to persist myThread itself not to the Session but to a database so
that I can maintain a reference to it. I can't serialize it and put
it in a database because the serialization would make me lose the
reference to the actual instance of myThread that I want so I'm
guessing I have to use JDO.

First, would you agree with my assumptions and approach to the
problem? Second, can I accomplish persisting the myThread object to a
database with Hibernate or some open source JDO implementation? If
so, could you provide an example on how to persist an object so that I
can retrieve the actual reference to the object I persisted and not
just a different instantiated class that is a clone of the original?

Thanks for your help. Please cc (e-mail address removed) on your
responses.

Mike
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top