Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Cleanup all threads on #close()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kelly committed May 26, 2014
1 parent 21af457 commit 7f11511
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -215,6 +215,10 @@ public void run() {
public void close() throws IOException {
deleteBatchExecutor.shutdown();
try {
if (!deleteBatchExecutor.awaitTermination(1, TimeUnit.SECONDS)) {
deleteBatchExecutor.shutdownNow(); // may need to interrupt take
}

if (!deleteBatchExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
LOG.warn("Delete executor did not shutdown");
}
Expand Down
10 changes: 9 additions & 1 deletion tso-client/src/main/java/com/yahoo/omid/client/TSOClient.java
Expand Up @@ -82,6 +82,7 @@ public class TSOClient {

private ChannelFactory factory;
private ClientBootstrap bootstrap;
private final ScheduledExecutorService fsmExecutor;
Fsm fsm;

private final int requestTimeoutMs;
Expand Down Expand Up @@ -165,7 +166,7 @@ private TSOClient(Configuration conf, MetricRegistry metrics) {

addr = new InetSocketAddress(host, port);

ScheduledExecutorService fsmExecutor = Executors.newSingleThreadScheduledExecutor(
fsmExecutor = Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("tsofsm-%d").build());
fsm = new FsmImpl(fsmExecutor);
fsm.setInitState(new DisconnectedState());
Expand Down Expand Up @@ -214,6 +215,12 @@ public TSOFuture<Long> commit(long transactionId, Set<? extends CellId> cells) {
public TSOFuture<Void> close() {
CloseEvent closeEvent = new CloseEvent();
fsm.sendEvent(closeEvent);
closeEvent.addListener(new Runnable() {
@Override
public void run() {
fsmExecutor.shutdown();
}
}, fsmExecutor);
return new ForwardingTSOFuture<Void>(closeEvent);
}

Expand Down Expand Up @@ -323,6 +330,7 @@ public void operationComplete(ChannelFuture future) throws Exception {
});
return new ConnectingState(retries - 1);
} else if (e instanceof CloseEvent) {
factory.releaseExternalResources();
((CloseEvent)e).success(null);
return this;
} else {
Expand Down

0 comments on commit 7f11511

Please sign in to comment.