Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

aborting a process in java

 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am reading data from MS-SQL6.5 DB and transferring those data into a XML file.The whole process is done by click of a button.While writing the data into the XML file,i want to provide the option of aborting that process.I use java IO to write data into the file.How can i achieve the functionality of aborting the "file writing" process?can anyone suggest godd program logic for this ?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest that you delegate the writing part to a dedicated thread. The run of that thread should be controlled by a boolean condition, like while(!buttonPressed). When you press the abort button you should switch the value of buttonPressed from false to true, thus aborting the thread. You should know, though, that this would let the file being written in a unknown state ! I think you don't care !
Let me know if it's not clear
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you read the Swing tutorial, especially the section about threads and Swing. The SwingWorker class mentioned there may serve you well. Top it off with the bit about progress bars and this bit about threads and you should be well-equipped for your journey.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic