You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tubemq.apache.org by "Guo Jiwei (Jira)" <ji...@apache.org> on 2020/04/13 14:59:00 UTC
[jira] [Created] (TUBEMQ-66) TubeSingleSessionFactory shutdown bug
Guo Jiwei created TUBEMQ-66:
-------------------------------
Summary: TubeSingleSessionFactory shutdown bug
Key: TUBEMQ-66
URL: https://issues.apache.org/jira/browse/TUBEMQ-66
Project: Apache TubeMQ
Issue Type: Bug
Reporter: Guo Jiwei
Assignee: Guo Jiwei
1. TubeSingleSessionFactory could not shutdown
due to we increase referenceCounter after first constructor method:
{code:java}
public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig) throws TubeClientException {
if (referenceCounter.incrementAndGet() == 1) {
RpcConfig config = TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
clientFactory.configure(config);
//#1
referenceCounter.incrementAndGet();
baseSessionFactory = new TubeBaseSessionFactory(clientFactory, tubeClientConfig);
}
}
{code}
{code:java}
public void shutdown() throws TubeClientException {
if (referenceCounter.decrementAndGet() > 0) {
return;
}
baseSessionFactory.shutdown();
clientFactory.shutdown();
}
{code}
We can fix it only remove #1, but I think this is not the best implementation for TubeSingleSessionFactory. How about do it like below :
{code:java}
private static final AtomicBoolean isStarted = new AtomicBoolean(false);
private static TubeBaseSessionFactory baseSessionFactory;
public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig) throws TubeClientException {
if (isStarted.compareAndSet(false, true)) {
RpcConfig config = TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
clientFactory.configure(config);
baseSessionFactory = new TubeBaseSessionFactory(clientFactory, tubeClientConfig);
}
}
@Override
public void shutdown() throws TubeClientException {
if (isStarted.compareAndSet(true, false)) {
baseSessionFactory.shutdown();
clientFactory.shutdown();
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)