diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionIn.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionListener.java | 7 | ||||
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | 11 |
3 files changed, 8 insertions, 12 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java index 6bb81b0de..3fd514d0d 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java @@ -90,7 +90,7 @@ public class ConnectionIn extends Connection implements Runnable { c.sendDialbackVerify(streamID, dbKey); } else { c = new ConnectionOut(dfrom, streamID, dbKey); - new Thread(c).start(); + XMPPComponent.executorService.submit(c); } } else { throw new Exception("STREAM FROM " + dfrom + " " + streamID + " DIALBACK RESULT FAIL"); diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java index 982f2efca..de11f9a38 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java @@ -17,22 +17,19 @@ public class ConnectionListener implements Runnable { private static final Logger logger = Logger.getLogger(ConnectionListener.class.getName()); - ExecutorService connectionPool; - @Override public void run() { try { - connectionPool = Executors.newCachedThreadPool(); final AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open(); listener.bind(new InetSocketAddress(5269)); logger.info("s2s listener ready"); listener.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() { @Override public void completed(AsynchronousSocketChannel result, Object attachment) { - listener.accept(connectionPool, this); + listener.accept(XMPPComponent.executorService, this); ConnectionIn client = new ConnectionIn(result); XMPPComponent.addConnectionIn(client); - connectionPool.submit(client); + XMPPComponent.executorService.submit(client); } @Override diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java index 3720d9635..9be8c744b 100644 --- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java @@ -24,7 +24,7 @@ public class XMPPComponent implements ServletContextListener { private static final Logger LOGGER = Logger.getLogger(XMPPComponent.class.getName()); - ExecutorService executorService; + public static final ExecutorService executorService = Executors.newCachedThreadPool(); public static String HOSTNAME = null; public static String STATSFILE = null; @@ -143,7 +143,7 @@ public class XMPPComponent implements ServletContextListener { } if (!haveAnyConn) { - new Thread(new ConnectionOut(hostname)).start(); + XMPPComponent.executorService.submit(new ConnectionOut(hostname)); } } @@ -151,7 +151,6 @@ public class XMPPComponent implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { LOGGER.info("component initialized"); - executorService = Executors.newSingleThreadExecutor(); executorService.submit(() -> { Properties conf = new Properties(); try { @@ -167,9 +166,9 @@ public class XMPPComponent implements ServletContextListener { childParsers.put(JuickMessage.XMLNS, new JuickMessage()); connRouter = new ConnectionRouter(componentName); - new Thread(connRouter).start(); - new Thread(new ConnectionListener()).start(); - new Thread(new CleaningUp()).start(); + executorService.submit(connRouter); + executorService.submit(new ConnectionListener()); + executorService.submit(new CleaningUp()); } catch (IOException | ClassNotFoundException | SQLException e) { LOGGER.log(Level.SEVERE, "XMPPComponent error", e); } |