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.
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
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.