Hi,
I’‘m trying to send a lot of messages one after another using Smack, but the sending doesn’'t occur untill I added a Thread.sleep delay in the loop. The funny thing is that even 1 ms delay is enough. Can anyone axplain me this ?
Code :
try
{
if(con == null || !con.isConnected()) con = new XMPPConnection(server);
if(!con.isAuthenticated()) con.login(senderId, password);
Message message = new Message();
message.setSubject(prepareSubject(evt));
for(User user:users)
{
LOG.info(MessageFormat.format(“Start sending Jabber notification to user : {0}”, user.getJabberId()));
message.setBody(prepareContent(evt, user));
try
{
con.createChat(MessageFormat.format("{0}@", user.getJabberId(), server)).sendMessage(message);
}
catch (XMPPException exc)
{
LOG.error(MessageFormat.format(“Failed to send Jabber notification to {0}”, user.getJabberId()), exc);
}
//noinspection EmptyCatchBlock
try
{
Thread.sleep(1);
}
catch (InterruptedException e) {}
LOG.info(“Jabber notification sent successfully.”);
}
}
catch (XMPPException exc)
{
LOG.error(“Failed to create Jabber connection”, exc);
}