On Sun, Mar 29, 2015 at 5:17 PM, Madhur Ahuja <ahuja.mad...@gmail.com> wrote:
> We have built a messaging server using PubNub which listens for chat > messages from Android device. > For this, our J2EE based spring, we have created a Pubnub listener (which > is basically a listening socket) > as follows. However, we have observed is that our server stops listening > randomly after few days. The > Tomcat keeps working fine, but just the socket stops listening. There is > not error in logs. > > Can anyone help in diagnosing this issue? Specifcally, I want to ensure > that the below design to initiate a listener is durable and not prone > to errors. > Seems the issue is with your application not Tomcat. Maybe try WebSocket? > > public class IncomingListener implements ApplicationListener < > ContextRefreshedEvent > { > > @Override > public void onApplicationEvent(ContextRefreshedEvent event) { > > private static volatile boolean isContextLoaded = false; > > @Autowired > ServletContext application; > > synchronized(IncomingListener.class) { > > if (isContextLoaded) { > System.out.println("WTF: Not initializing incoming > listener"); > return; > } > try { > initialiseIncomingListener(); > isContextLoaded = true; > } catch (JSONException e) { > e.printStackTrace(); > } catch (AkoshaException e) { > e.printStackTrace(); > } > > } > } > > private void initialiseIncomingListener() > { > // Initialize our Pubnub Listener > > pubnub.subscribe(serverchannel, new Callback() { > > // Subscribe to pubnub > }); > } > } > -- Marcos | I love PHP, Linux, and Java <http://javadevnotes.com/java-string-to-double-examples>