Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2006

Tip: Looking for answers? Try searching our database.

Creating new thread from servlet

Thread view: 
hust6 - 15 Aug 2006 21:53 GMT
I am looking for some general suggestions on how to do a task:

I have a Java servlet running in Tomcat that is a form.  Users come to
the page and fill out the form, and my servlet puts the information
into a database.  My issue has to deal with a class I need to call
before entering the data in the database, which takes a little bit of
time to execute, thus the submission of the form takes a long time.
This can be called at ANY time, however.

Therefore, I want to be able to spawn a new thread to execute that
class/process right when the form is loaded, so my process can execute
while the user is filling out the form so that it is done (or almost
done) by the time they submit the form.  How would you go about doing
that?

I think I know how to call a new thread to start the process, but how
can I make sure that after they hit "submit" on my form, that the other
thread is done before the data is entered into the database?

I hope I am clear enough.

Thanks for the help.
Rohit Kumbhar - 15 Aug 2006 23:09 GMT
> I am looking for some general suggestions on how to do a task:
>
[quoted text clipped - 9 lines]
> done) by the time they submit the form.  How would you go about doing
> that?

I am assuming that you have a particular task which needs to be done for
a particular form [load-submit/request-response] combination, per
request. I would do it this way [if at all this is the only way to do it]:

Have two different URL strings [may use the same servlet though] for
form-load and form-submit actions.

URL is for form-load: Start the threaded task and cache the thread-id or
the runnable object or thread complete flag with some unique key [say,
session id].
URL is for form-submit: Get the id/object/flag for the key, do the
required checks and update the database.

> I think I know how to call a new thread to start the process, but how
> can I make sure that after they hit "submit" on my form, that the other
> thread is done before the data is entered into the database?

To achieve this, a simple flag should do the trick. Note, you will need
to cache the flags per request to the form.

> I hope I am clear enough.
>
> Thanks for the help.

Regards
Rohit


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.