From 2262c9c81fee46f21b3f1f2f3441cdfd41cb1f64 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 1 Aug 2016 16:43:39 +0300 Subject: www: Thread -> ExecutorService --- juick-www/src/main/java/com/juick/www/Main.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'juick-www') diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index e3457323..d8096ff4 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -37,6 +37,8 @@ import java.net.Socket; import java.net.URLEncoder; import java.util.Objects; import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @@ -64,6 +66,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { SignUp signup = new SignUp(); Settings settings = new Settings(); RSS rss = new RSS(); + ExecutorService executorService = Executors.newSingleThreadExecutor(); @Override public void init() throws ServletException { @@ -98,8 +101,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { } } + @Override + public void destroy() { + executorService.shutdownNow(); + super.destroy(); + } + public void setupXmppComponent(final JID componentJid, final String password) { - Thread thr = new Thread(() -> { + executorService.submit(() -> { try { Socket socket = new Socket("localhost", 5347); xmpp = new StreamComponent(componentJid, socket.getInputStream(), socket.getOutputStream(), password); @@ -109,7 +118,6 @@ public class Main extends HttpServlet implements Stream.StreamListener { log("XMPP is not initialized"); } }); - thr.start(); } @Override -- cgit v1.2.3