From 6c8b3cdf36d33e3da2ae94a5ef89243579a57b89 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 1 Dec 2016 17:04:59 +0300 Subject: juick-api: start telegram bot in different thread --- juick-api/src/main/java/com/juick/api/TGBot.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'juick-api/src/main/java/com/juick/api') diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java index d532b02c..bbfed259 100644 --- a/juick-api/src/main/java/com/juick/api/TGBot.java +++ b/juick-api/src/main/java/com/juick/api/TGBot.java @@ -24,6 +24,8 @@ import javax.inject.Inject; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static com.juick.formatters.PlainTextFormatter.formatPost; import static com.juick.formatters.PlainTextFormatter.formatUrl; @@ -43,6 +45,8 @@ public class TGBot implements AutoCloseable { @Inject MessagesService messagesService; + ExecutorService service = Executors.newSingleThreadExecutor(); + private TGBot() { throw new IllegalStateException(); } @@ -102,7 +106,7 @@ public class TGBot implements AutoCloseable { } } }); - ws.connect(); + service.submit(() -> ws.connect()); } catch (Exception e) { logger.warn("couldn't initialize telegram bot", e); } -- cgit v1.2.3