File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes aborting a process in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "aborting a process in java" Watch "aborting a process in java" New topic

aborting a process in java

Vaskar Dasgupta

Joined: Jul 20, 2001
Posts: 25
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 ?

Kindly reply back.
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
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
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform

[Blog] [Blogroll] [My Reviews] My Linked In
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
I agree. Here's the link:
subject: aborting a process in java
It's not a secret anymore!