Back to project page msghandle.
The source code is released under:
GNU General Public License
If you think the Android project msghandle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.anlong.msghandle.common; //from w w w . ja va 2s .co m import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.anlong.msghandle.util.IMLog; import com.anlong.msghandle.util.Utils; /** * @ClassName: MessageTimer * @Package: com.anlong.imsghandle.common * @company ShenZhen anlong Technology CO.,LTD. * @Description: TODO ???????????? * @author anlong * @date 2013-6-1 ????2:18:09 * @version V1.0 */ public class MessageTimer extends HandleTimer implements Runnable { // ???????? private static Map<String,Long> timeMap = new HashMap<String, Long>(); // ??KEY???? private static List<String> keyList = new ArrayList<String>(); public MessageTimer(){} @Override public void run() { while (true) { // TODO ????????? long endTime = System.currentTimeMillis(); runTimerResult(endTime); try { //TODO ??????1? ????????CPU?2013?7?5????????? Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } @Override public void startTimer(String key, String bCode){ // TODO ?????? long startTime = System.currentTimeMillis(); keyList.add(key); timeMap.put(key, startTime); IMLog.anlong("????" + bCode+ "???????????,???????" + key +", ??"+ keyList.size() +" ??????????."); } @Override public void cancelTimer(String key){ IMLog.anlong("????????,???????" + key); timeMap.remove(key); keyList.remove(key); } /** * The difference between the two time * @author anlong * @throws */ private void runTimerResult(long endTime){ if(keyList == null || keyList.size() == 0) return ; if(timeMap == null || timeMap.size() == 0) return; for (int i = 1; i < keyList.size(); i++) { String key = keyList.get(i); if(Utils.isNull(key)) continue; long startTime = timeMap.get(key); if(Utils.isNull(startTime)){ continue; } if((endTime - startTime)>HandleStaticValue.MESSAGE_RESPONSE_TIMEOUT){ cancelTimer(key); Utils.notifyMessage(key, HandleStaticValue.BCODE1003); } } } }