List list=new ArrayList();
HashMap hmap=new HashMap();
Timer time=new Timer();
if(!tast.stat)
{
time.schedule(tast.getInStance(),(long)1000,(long)3000);
}
hmap=BusCache.getInStance().getLineMap();
if(hmap.isEmpty())
{
hmap=(new HashTest()).findBusState();    //获得所有新路相关信息的map
}
else
{
hmap=BusCache.getInStance().getLineMap();
}
BusStateBean busStateBean=null;
String linenos[]=lineno.split(",");    //切割传过来的线路串
if(!hmap.isEmpty())
{
for(int k=0;k<linenos.length;k++)
{
Iterator iterator = hmap.keySet().iterator();
while (iterator.hasNext()) {
String key = (String)iterator.next();
String[] items = key.split(",");
    if(linenos[k].equals(items[0]))  //判断是否有map缓存中是否有存在的线路
{
busStateBean=(BusStateBean)hmap.get(key);
list.add(busStateBean);
}
}
}
}

解决方案 »

  1.   

    tast 类
    public class tast extends TimerTask {
    public static boolean stat=false;
    private static tast me;
    private tast(){

    }
    public static tast getInStance() {
    if (me == null)
    {
    me = new tast();
    }
    return me;
    }
     public void run(){
     HashMap hmap=new HashMap();
    hmap=BusCache.getInStance().getLineMap();
    if(hmap.isEmpty())
    {
    hmap=(new BusInfoDao()).findBusState();    //获得所有新路相关信息的map
    }
    else
    {
    hmap.clear();
    hmap=(new BusInfoDao()).findBusState();
    }
    stat=true;
      
     }
    }
      

  2.   

    出现的错误java.util.ConcurrentModificationException
    java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
    java.util.HashMap$KeyIterator.next(HashMap.java:823)
    commsoft.yy.run.HashTestXml.doGet(HashTestXml.java:81)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    commsoft.framework.filters.SetCharacterEncodingFilter.doFilter(DashoA10*..)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)这是什么原因造成的啊?
      

  3.   

    给你个传送门http://xiaoruanjian.javaeye.com/blog/878721
      

  4.   

    兄弟这个类你用的到,java.util.Collections