I am making a call to an api, which handles the uploading of a file. I would like to be able to cancel the upload upon user request. But, the api is poorly implemented, it does not expose an sort of a cancel method. Once the upload is started, there is no way to force it stop. Any suggestions about what I could do?
What makes some sense to me is to do something along the lines of making the upload call in a
thread, keeping a reference to the thread, and killing upon user request. But, according to the
java api, this is a bad idea:
"
stop()
Deprecated. This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the unchecked ThreadDeath exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, potentially resulting in arbitrary behavior. Many uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable, for example), the interrupt method should be used to interrupt the wait.
"
Modifying a global variable doesn't get me anywhere. Because the upload is happening inside the api, which is code that I can not modify. Help please?
Thank you