> From: "Tam, Michael" <[EMAIL PROTECTED]>
> Sent: Friday, March 21, 2003 12:06 PM


> Or better, what is the best way to spawn another process to perform the
> validation and loading after the files being uploaded to avoid the client
> interferes the process accidentally?

The best way to do what you propose is have your Servlets upload the data
and then place a request for the further processing into a queue. At that
point you return to client saying "Processing you request, come back
later..." or some such thing. It obviously depends on whether the client
actually cares about the outcome or not.

Then on the other end of the queue is a process taking requests, performing
further processing on them and perhaps updating the status of the overall
job (so it can report it back to the client if they ask for it).

There are several ways you can do this kind of thing.

One, is to have the queue be a simple container (like an ArrayList) that has
it's overall access guarded by synchronized methods. This queue live within
the JVM, and another thread can be running endlessly querying the queue for
requests, and then acting upon them.

Another technique is to have the queue implemented within a database, and
then a completely seperate process, written in anything that can access the
database, can get access to the jobs and process them.

The Java Way of doing this kind of the is with JMS, which allows you to
abstact the whole queuing and monitoring aspects of the system. Here you
have a Publisher, which creates requests, and Subscribers, which act upon
then. Depending on the JMS system, these can all be within the same JVM, or
on completely different machines. It also makes it easy to have several
Subscribers acting upon the same Topic. A contrived example would be that
you have your Servlet acting as a Publisher, adding request as fast as your
users can submit them. Then, since your processing is CPU intensive, you set
up 10 different machines, each having the bandwidth to process 3 different
requests simultaneously. So, each machine creates 3 Subscribers, and you end
up with 30 Subscribers total.

The JMS system is fine way to pull things like this off, and the various
implementations have assorted features that differ on robustness,
scalability and performance.

However, if it were me, I'd probably roll my own simple queue and fire off a
couple of processing threads within the JVM of the Servlet container, have a
Servlet that initializes this whole thing loaded-at-startup within the
web.xml and be done with it. Make sure you persist the requests that have
not been processed yet so should the Servlet container quit, you can reload
and process those requests later after restart.

Like I said, JMS does exactly what you want, but if your needs are fairly
limited, writing your own is not overly complicated. A simple queue, a few
threads, a little DB work.

http://openjms.sourceforge.net/ is a free implementation, though I have not
used it.

Regards,

Will Hartung
([EMAIL PROTECTED])




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to