Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet and thread clarification

 
sai prasad tangirala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

Thanks,
Sai
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tatha Roy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Thanks
 
suraj aryan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know the thread name for which task it is created and so can use its object .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic