aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/push
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2015-12-01 13:51:43 +0300
committerGravatar Vitaly Takmazov2015-12-01 13:51:43 +0300
commitbb164c441d110cf7bd4ce33dfab0ff184010647d (patch)
treea134ef6f850a9ff66fa1689e1ea6efe95b02f698 /src/main/java/com/juick/push
parent8e3089b0397486275883e8587adc277563e1405c (diff)
PushComponent: executor service
Diffstat (limited to 'src/main/java/com/juick/push')
-rw-r--r--src/main/java/com/juick/push/PushComponent.java34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main/java/com/juick/push/PushComponent.java b/src/main/java/com/juick/push/PushComponent.java
index 6f857f598..a32e887ce 100644
--- a/src/main/java/com/juick/push/PushComponent.java
+++ b/src/main/java/com/juick/push/PushComponent.java
@@ -48,6 +48,8 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -59,30 +61,38 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
private static Logger logger = Logger.getLogger(PushComponent.class.getName());
+ private ExecutorService executorService;
Connection sql;
Socket socket;
Stream xmpp;
Sender GCMSender;
@Override
- public void contextInitialized(ServletContextEvent sce) {
+ public void contextInitialized(final ServletContextEvent sce) {
logger.info("component initialized");
- Properties conf = new Properties();
- try {
- conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/push.conf"));
- GCMSender = new Sender(conf.getProperty("gcm_key"));
+ executorService = Executors.newSingleThreadExecutor();
+ executorService.submit(new Runnable() {
+ @Override
+ public void run() {
+ Properties conf = new Properties();
+ try {
+ conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/push.conf"));
+ GCMSender = new Sender(conf.getProperty("gcm_key"));
- setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"),
- conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", ""));
- setupXmppComponent(new JID("", conf.getProperty("xmpp_jid"), ""), conf.getProperty("xmpp_host", "localhost"),
- Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("xmpp_password", ""));
- } catch (IOException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
+ setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"),
+ conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", ""));
+ setupXmppComponent(new JID("", conf.getProperty("xmpp_jid"), ""), conf.getProperty("xmpp_host", "localhost"),
+ Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("xmpp_password", ""));
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ }
+ }
+ });
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
+ executorService.shutdown();
logger.info("component destroyed");
}