Skip to content

Commit

Permalink
FABJ-389 shutdown threadExecutor
Browse files Browse the repository at this point in the history
PS
02 Odd javadoc now getting flagged.

Change-Id: I4a6d5287c56a5e5245f7a766dc4f9635b63c6104
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Dec 12, 2018
1 parent b9f61bd commit c30a34e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -195,6 +196,7 @@ public class Channel implements Serializable {
private transient LinkedHashMap<String, LinkedList<TL>> txListeners = new LinkedHashMap<>();
//Cleans up any transaction listeners that will probably never complete.
private transient ScheduledFuture<?> sweeper = null;
private transient ScheduledExecutorService sweeperExecutorService;
private transient String blh = null;
private transient ServiceDiscovery serviceDiscovery;

Expand Down Expand Up @@ -4195,14 +4197,14 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
/**
* NofEvents may be used with @see {@link TransactionOptions#nOfEvents(NOfEvents)} to control how reporting Peer service events and Eventhubs will
* complete the future acknowledging the transaction has been seen by those Peers.
* <p/>
* <p>
* You can use the method @see {@link #nofNoEvents} to create an NOEvents that will result in the future being completed immediately
* when the Orderer has accepted the transaction. Note in this case the transaction event will be set to null.
* <p/>
* <p>
* NofEvents can add Peer Eventing services and Eventhubs that should complete the future. By default all will need to
* see the transactions to complete the future. The method @see {@link #setN(int)} can set how many in the group need to see the transaction
* completion. Essentially setting it to 1 is any.
* </p>
* <p>
* NofEvents may also contain other NofEvent grouping. They can be nested.
*/

Expand Down Expand Up @@ -4569,7 +4571,7 @@ public TransactionOptions shuffleOrders(boolean shuffleOrders) {
* This maybe set to NOfEvents.nofNoEvents that will complete the future as soon as a successful submission
* to an Orderer, but the completed Transaction event in that case will be null.
*
* @param nOfEvents @see {@link NOfEvents}
* @param nOfEvents See @see {@link NOfEvents}
* @return This TransactionOptions
*/
public TransactionOptions nOfEvents(NOfEvents nOfEvents) {
Expand Down Expand Up @@ -5328,11 +5330,12 @@ void runSweeper() {

if (sweeper == null) {

sweeper = Executors.newSingleThreadScheduledExecutor(r -> {
sweeperExecutorService = Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}).scheduleAtFixedRate(() -> {
});
sweeper = sweeperExecutorService.scheduleAtFixedRate(() -> {
try {

if (txListeners != null) {
Expand Down Expand Up @@ -5646,6 +5649,12 @@ public synchronized void shutdown(boolean force) {
if (null != lsweeper) {
lsweeper.cancel(true);
}

ScheduledExecutorService lse = sweeperExecutorService;
sweeperExecutorService = null;
if (null != lse) {
lse.shutdownNow();
}
}

/**
Expand Down

0 comments on commit c30a34e

Please sign in to comment.