Problem with Smack API in web application

I need to register users and send the message to them jabber on this web environment but the API does not work as often sends as many times not send this totally unstable … And to detect the presence of a user have to put a thread.sleep (500) only the presence comes null someone help me?

Thanks

Oi Luis,

Could you paste a sample code that reproduces the problem and that we could analyze?

Obrigado,

– Gato

while (iter.hasNext()) {

RosterEntry entry = (RosterEntry) iter.next();

int index = Collections.binarySearch((List)colaboradores,entry.getUser(),comparator);

if (index > -1) {

try {

Thread.sleep(500);

} catch (InterruptedException e) {

e.printStackTrace();

}

Presence presence = roster.getPresence(entry.getUser());

System.out.println(“PRESENCE:”+presence);

if (presence != null && presence.getType() == Presence.Type.AVAILABLE) {

Message message = new Message();

message.setTo(entry.getUser());

message.setSubject(“Controle de Build”);

message.setBody(msg);

connection.sendPacket(message);

System.out.println(“ola”);

connection.addPacketWriterListener(new PacketListener(){

public void processPacket(Packet packet) {

if (packet instanceof Message) {

System.out.println(“Message is:”+((Message)packet).getBody());

connection.sendPacket(packet);

System.out.println(“ola2”);

}

}

}, null);

try {

Thread.sleep(5000);

} catch (InterruptedException e) {

}

}

}

}

} catch (XMPPException e) {

e.printStackTrace();

} finally{

connection.close();

connection = null;

}

System.out.println(System.currentTimeMillis() - inicial);

}

this thread