Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Threads and Synchronization and the fly likes servlet and thread clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "servlet and thread clarification" Watch "servlet and thread clarification" New topic

servlet and thread clarification

sai prasad tangirala

Joined: Dec 05, 2007
Posts: 4
We are uploading a file to server and reading the uploaded file and we are reading the file and inserting into database. When it is a large file insertion takes some time during which user can cancel the operation and we need to stop the process. We are planning to have a thread created for insertion. Suppose the thread is running at this point of time and cancel is done from UI which will fire another request. I can stop the thread but how can i get the thread object as there will be n number of threads running at a point of time? Kindly throw some light on this.

Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 438

You really need to ask this question in another forum.

Presuming your using a web server , obviously depends on which one and J2EE version available (and possibly if its clustered) but basically you should be trying to avoid creating a thread as such (get the container to do it) , basically get the work manager (if the container supports one) and submit a unit of work.

How you reference the work / thread later is via the session.

Again your probably best asking this in a another forum servlets or EJB and other technologies.

"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Welcome to JavaRanch..

Why not set the name of the thread while creating a new thread for insertation and use the same name while stop the specific thread

SCJP6.0,My blog Ranchers from Delhi
Tatha Roy

Joined: Oct 28, 2010
Posts: 3

Your problem seems to be of one which i had faced in my previous project. For this kind of task if you can have the handle to the running threads then it is possible to set a variable in the thread. In our case we had a volatile boolean variable in the thread class which can be set to true or false based on whether the request is for start or stop. The running thread before doing a the insert statement should always look whether the variable is set. If so you can exit after commit. I hope it solves the problem.

suraj aryan

Joined: Nov 19, 2010
Posts: 24
You know the thread name for which task it is created and so can use its object .
I agree. Here's the link:
subject: servlet and thread clarification
jQuery in Action, 3rd edition