This doesn't seem a good way to implement that functionality. The
interrupt() method of a
thread should generally be called by another thread to stop the target thread from whatever it is doing at the moment. This is not your case.
I'll describe how I usually go about this in my programs, but this is by no means the only possibility, and in all probability not the best possibility at all. You also need to figure on your own how to fit this scenario onto your object model, if you choose to do it this way.
I'd create a method called, say,
canClose, which would return a
boolean. This method returns
true if the document can be closed,
false otherwise. Whichever operation that results into closing a document (closing the window, opening a new document and so on) calls this method and if it returns
false, it simply aborts the operation.
Now if the document in question is modified, the
canClose method displays the standard message box ("Document was modified. Save? Yes/No/Cancel"). If the user presses
No or
Cancel,
true or
false (respectively) is immediately returned. If the user presses
Yes, the document's
save() method is called. If it succeeds,
true is returned, if it fails (assuming a save operation can fail, which it usually can), it returns
false, therefore preventing closing of a document that was not successfully saved.
You may add a parameter to the method indicating the action that is behind the call, if you want to customize the message displayed to the accordingly.