@Override public void run() { while (containUndeleted(statuses)) { LOG.debug("(Thread-" + Thread.currentThread().getName() + ")delete weibo"); for (int i = 0; i < statuses.size(); i++) { Status s = statuses.get(i); if (s.isDeleted()) continue; Status ds = null; try { if (!outOfLimit) { LOG.debug("deleting " + (destroyedIndex + 1) + "st weibos, status.id=:" + s.getId()); ds = tm.Destroy(s.getId()); s.setDeleted(true); statuses.set( i, s); // in OOP(Object Oriented Programming), it will changes table(type of List) // which in repository(type of Map) // weiboPersistenceService.save(statues); in procedure oriented programming, it should // be save by PersistenceService; destroyedIndex++; } else { LOG.debug("not be deleted:status.id=" + s.getId()); } } catch (WeiboException e) { String error = e.toString(); if (error.indexOf("target weibo does not exist!") != -1) LOG.error( "an error eccorred when delete weibo,status.id=" + s.getId() + " this weibo does not exist"); else if (error.indexOf("User requests out of rate limit!") != -1) { LOG.error( "an error(\"User requests out of rate limit!\") eccorred when delete weibo,status.id=" + s.getId() + " " + e); outOfLimit = true; // ju.setOutOfLimit(true); // jcUserPersistenceService.delete(ju); // jcUserPersistenceService.save(ju); LOG.debug("follow ids are not be delete:"); } } } if (outOfLimit == true) { // if (!ju.isOutOfLimit()) { LOG.debug("take a break for a half hour,it has delete count=" + (destroyedIndex + 1)); try { Thread.sleep(1800 * 1000); outOfLimit = false; // ju.setOutOfLimit(true); // jcUserPersistenceService.delete(ju); // jcUserPersistenceService.save(ju); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } weiboPersistenceService.deleteStatuses(statuses); LOG.debug("(Thread-" + Thread.currentThread().getName() + ")delete completed."); LOG.debug("(Thread-" + Thread.currentThread().getName() + ")delete completed."); }
public boolean containUndeleted(List<Status> statuses) { for (Status s : statuses) { if (!s.isDeleted()) return true; } return false; }