List of usage examples for org.apache.commons.collections Bag clear
void clear();
From source file:com.pureinfo.tgirls.utils.counts.CountsJob.java
public void execute() { logger.debug("to process counts."); CountsProcess cache = CountsProcess.getInstance(); Bag bag = new HashBag(); synchronized (cache) { bag.addAll(cache.getBag());//from ww w .jav a2 s . c o m cache.clear(); } ISession session = null; try { session = LocalContextHelper.currentSession(); Set<String> bagKeySet = bag.uniqueSet(); for (Iterator<String> iterator = bagKeySet.iterator(); iterator.hasNext();) { String type = null; try { type = iterator.next(); Counts counts = new Counts(); counts.setType(type); counts.setCounts(bag.getCount(type)); counts.setCreateTime(); session.save(counts); } catch (Exception e) { logger.error("error when save counts:" + type, e); } } } catch (Exception e) { logger.error("error occur.", e); } finally { bag.clear(); if (session != null) try { session.close(); } catch (Exception e) { logger.error("error when close session.", e); } } }