mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-20 13:34:42 +01:00
ForwardingService: improve the implementation of close()
* Don't try to remove listener (access .wallet()) unless kit.isRunning() * Don't wait for termination, just call kit.stopAsync() * Add some JavaDoc
This commit is contained in:
parent
498d638915
commit
fb6add760b
1 changed files with 11 additions and 2 deletions
|
@ -133,11 +133,20 @@ public class ForwardingService implements AutoCloseable {
|
|||
kit.wallet().addCoinsReceivedEventListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the service. {@link AutoCloseable} will be triggered if an unhandled exception occurs within
|
||||
* a <i>try-with-resources</i> block.
|
||||
* <p>
|
||||
* Note that {@link WalletAppKit#setAutoStop(boolean)} is set by default and installs a shutdown handler
|
||||
* via {@link Runtime#addShutdownHook(Thread)} so we do not need to worry about explicitly shutting down
|
||||
* the {@code WalletAppKit} if the process is terminated.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
kit.wallet().removeCoinsReceivedEventListener(listener);
|
||||
if (kit.isRunning()) {
|
||||
kit.wallet().removeCoinsReceivedEventListener(listener);
|
||||
}
|
||||
kit.stopAsync();
|
||||
kit.awaitTerminated();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue