XmmppManager.RegisterTask 方法问题
XmmppManager.RegisterTask 方法
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
//添加锁
synchronized (xmppManager) {
if (packet instanceof IQ) {
IQ response = (IQ) packet;
if (response.getType() == IQ.Type.ERROR) {
if (!response.getError().toString().contains(
"409")) {
Log.e(LOGTAG,
"Unknown error while registering XMPP account! "
+ response.getError()
.getCondition());
}
} else if (response.getType() == IQ.Type.RESULT) {
xmppManager.setUsername(newUsername);
xmppManager.setPassword(newPassword);
Log.d(LOGTAG, "username=" + newUsername);
Log.d(LOGTAG, "password=" + newPassword);
Editor editor = sharedPrefs.edit();
editor.putString(Constants.XMPP_USERNAME,
newUsername);
editor.putString(Constants.XMPP_PASSWORD,
newPassword);
editor.commit();
isRegisterSucceed=true;
Log
.i(LOGTAG,
"Account registered successfully");
xmppManager.runTask();
}
}
}
}
};
connection.addPacketListener(packetListener, packetFilter);
registration.setType(IQ.Type.SET);
// registration.setTo(xmppHost);
// Map<String, String> attributes = new HashMap<String, String>();
// attributes.put("username", rUsername);
// attributes.put("password", rPassword);
// registration.setAttributes(attributes);
registration.addAttribute("username", newUsername);
registration.addAttribute("password", newPassword);
connection.sendPacket(registration);
//睡眠线程
try {
Thread.sleep(10*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//该方法也可能出现问题,在10s之后,比如10.1s 客户端获得了服务器的数据,开始了监听,那么 xmppManager.runTask();就会重复被执行????
synchronized(xmppManager){
if (!isRegisterSucceed) {
xmppManager.dropTask(1);
xmppManager.runTask();
xmppManager.startReconnectionThread();
}
}
还有一种问题,在10s之后,下面同步代码块已经走完了,比如10.1s ,客户端获得了服务器的数据,开始了监听,那么 xmppManager.runTask();就会重复被执行?????