Skip to content

Commit f311baa

Browse files
author
Igor Polevoy
committed
#370 Implement closing of all resources in Async on stop() method.
1 parent 1a316cc commit f311baa

File tree

1 file changed

+10
-0
lines changed
  • javalite-async/src/main/java/org/javalite/async

1 file changed

+10
-0
lines changed

javalite-async/src/main/java/org/javalite/async/Async.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class Async {
8181

8282
private List<QueueConfig> queueConfigsList = new ArrayList<>();
8383
private boolean started;
84+
private List<Session> sessions = new ArrayList<>();
85+
private List<MessageConsumer> messageConsumers = new ArrayList<>();
8486

8587
/**
8688
* Creates and configures a new instance.
@@ -208,6 +210,8 @@ private void configureListeners(Injector injector, List<QueueConfig> queueConfig
208210
Session session = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
209211
MessageConsumer consumer = session.createConsumer(queue);
210212
consumer.setMessageListener(listener);
213+
sessions.add(session);
214+
messageConsumers.add(consumer);
211215
}
212216
}
213217
}
@@ -331,6 +335,12 @@ public void start(){
331335
*/
332336
public void stop() {
333337
started = false;
338+
for (MessageConsumer messageConsumer : messageConsumers) {
339+
closeQuietly(messageConsumer);
340+
}
341+
for (Session session : sessions) {
342+
closeQuietly(session);
343+
}
334344

335345
closeQuietly(producerConnection);
336346
closeQuietly(consumerConnection);

0 commit comments

Comments
 (0)