سؤال

Here I am connecting to facebook using smack and servlets ,I can able to send and receive chat messages. But here connection object is instance variable(not thread-safe),so all the users are getting same connection object.

If we declare XMPPConnection object inside doGet() method we have to take connection every time when the user send chat message.

provide some solution for my problem.

public class Home_page_action extends HttpServlet  implements MessageListener{

 public XMPPConnection connection;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

               if(connection!=null)
               {connection.connect("uname","password");}
               else{
               //send message code to target user
                }


              }

}
هل كانت مفيدة؟

المحلول

Make some class to maintain pool of your connection and every time you have to just call getInstance of that class..

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top