iri
iri copied to clipboard
Closing of resources and Thread interrupt
Hi,
I'm a huge fan of your project and wanted to help a little bit. While going through a code analysis I found two things that can possibly end in a bug or make it harder to analyse bugs. First I've added closing of resources where it was missing. Second I've reinterrupted the Threads after an InterruptedException is thrown. See Don't swallow interrupts for more details on that.
Hope that it helps. Best wishes, Marcus
👎 on all the Thread.interrupt()
calls, they all go clearly against the original intentions on how to handle the InterruptedException
Would you please rebase your changes on top of the current dev branch?
I struggled a little bit with the rebase, but it's done now
Hey,
Sorry for the late response. Can you break this into two PRs? One for each subject.
Thanks
I think this pull request can be closed without merging with the following explanation:
There are three subjects in this pull request.
-
Re-interrupt thread after catching the
InterruptedException
.The only difference of re-interrupting is the
interrupted status
is set again. If the thread itself does not call methods likeinterrupted()
orisInterrupted()
, theinterrupted status
would not affect the thread execution. Even if the thread does call the methods, it would remain the same if no other threads can interrupt it.The result of tracing code:
-
Milestone.java No more try-catch of
InterruptedException
. -
IXI.java
-
TransactionValidator.java
-
PearlDiver.java
-
ReplicatorSinkProcessor.java
-
TipsManager.java -> TipsSolidifer.java The threads in the above files do not call methods like
interrupted()
orisInterrupted()
. -
ReplicatorSinkPool.java It uses
Thread.interrupted()
to decide the while loop execution. However, no other threads can interrupt it.A simple conclusion: The re-interruption is meaningful only if the thread uses
interrupted status
to change the flow of thread execution.
-
Close resource.
The file
FileExportProvider.java
is no longer existed. -
The other code refinement.
IRI has changed a lot since the pull request had been proposed. The code refinement had been integrated into IRI with a more elegant and simpler way.