Search code examples
javaparsingoperationcancel-button

Stopping/Interrupting an operation


I have a Java project that parses an html page using JSoup and writes some dates in an Excel spreadsheet (.xls file).

In the frame there is a button "Stop operation" so the user can stop the task but the button does not work until the parsing/writing has ended. "X button" in the frame has the same behavior.

Can someone help me to solve this?


Solution

  • You should put all the parsing and writing operation in an external thread, and then interrupt the thread if the user clicks on the Stop Operation button.

    Here's an example on how you can use the Thread interruption: http://www.tutorialspoint.com/javaexamples/thread_interrupt.htm