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();
???????????????? }
? ? ? ? ? ? ? ? //該方法也可能出現(xiàn)問題,在10s之后,比如10.1s 客戶端獲得了服務器的數(shù)據(jù),開始了監(jiān)聽,那么?xmppManager.runTask();就會重復被執(zhí)行????
? ? ? ? ? ? ? ? synchronized(xmppManager){
????????? ? ? ? ? ? ? ? if (!isRegisterSucceed) {
????????? ? ? ? ? ? ? ? ? ? xmppManager.dropTask(1);
????????? ? ? ? ? ? ? ? ? ? ? ? ?xmppManager.runTask();
????????? ? ? ? ? ? ? ? ? ? ? ? ?xmppManager.startReconnectionThread();
????????? ? ???????????? }
? ? ? ? ? ? ?}
還有一種問題,在10s之后,下面同步代碼塊已經(jīng)走完了,比如10.1s ,客戶端獲得了服務器的數(shù)據(jù),開始了監(jiān)聽,那么?xmppManager.runTask();就會重復被執(zhí)行?????
2015-11-12
重復執(zhí)行runtask 有問題??也不存在所謂重復的問題,有同步鎖,runtask取出的task肯定是不一樣的,是按照add到tasklist里面的順序取出執(zhí)行的,多runtask一次能有什么問題?畢竟都是要執(zhí)行的,有同步鎖和越界處理 ,能有什么問題
2015-06-05
我覺得這也是個bug,但是這種情況幾乎不存在,沒必要修復這個bug
2015-04-28
我也覺得存在這個問題