Ticket #147 (new Bug)

Opened 10 years ago

Last modified 10 years ago

产品库动态其中一台机负载高问题分析

Reported by: liaojunqiang Owned by:
Priority: major Milestone:
Component: 产品库 Version: 报价库5.0
Keywords: 死锁 非线程安全 Cc:
Due Date: 18/05/2016

Description (last modified by liaojunqiang) (diff)

网络反映pdlib有台机负载又比较高了,重启后正常,239.59,打开jdk-out.log,看到以下的线程比较多

cn.com.pconline.core.product.database.DbProduct.getMapProductItemWEBVisable (DbProduct.java:1205)

查看代码发现有成员变量被2个方法共用,某种特定情况下造成线程不安全,导致死锁

private Map mapProductItemWEB = new HashMap();	
	public Map getMapProductItemWEB(ConfigProfile cp) {
		if (mapProductItemWEB!=null && mapProductItemWEB.size()>0) return mapProductItemWEB;
		mapProductItemWEB = new HashMap();
		try {
			List items = getProductItemWEB(cp);
			for (Iterator it = items.iterator(); it.hasNext();) {
				ProductItemWEB piweb = (ProductItemWEB) it.next();
				/*if (mapProductItemWEB.get(piweb.getTitle()) == null && !piweb.isHidden())*/
                                String title = piweb.getTitle();
				if (mapProductItemWEB.get(title) == null)
					mapProductItemWEB.put(title, piweb);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapProductItemWEB;
	}
	
	private Map mapProductItemWEBVisable = new HashMap();
	
	public Map getMapProductItemWEBVisable(ConfigProfile cp) {
		if (mapProductItemWEB!=null && mapProductItemWEB.size()>0) return mapProductItemWEB;
		mapProductItemWEB = new HashMap();
		try {
			List items = getProductItemWEB(cp);
			for (Iterator it = items.iterator(); it.hasNext();) {
				ProductItemWEB piweb = (ProductItemWEB) it.next();
				if (mapProductItemWEB.get(piweb.getTitle()) == null && !piweb.isHidden())
					mapProductItemWEB.put(piweb.getTitle(), piweb);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapProductItemWEB;
	}
	

修改代码后更新,待观察

public Map getMapProductItemWEB(ConfigProfile cp) {
                Map mapProductItemWEB = new HashMap();	
		try {
			List items = getProductItemWEB(cp);
			for (Iterator it = items.iterator(); it.hasNext();) {
				ProductItemWEB piweb = (ProductItemWEB) it.next();
				/*if (mapProductItemWEB.get(piweb.getTitle()) == null && !piweb.isHidden())*/
                                String title = piweb.getTitle();
				if (mapProductItemWEB.get(title) == null)
					mapProductItemWEB.put(title, piweb);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapProductItemWEB;
	}
	
	
	public Map getMapProductItemWEBVisable(ConfigProfile cp) {
                Map mapProductItemWEBVisable = new HashMap();
		try {
			List items = getProductItemWEB(cp);
			for (Iterator it = items.iterator(); it.hasNext();) {
				ProductItemWEB piweb = (ProductItemWEB) it.next();
				if (mapProductItemWEBVisable.get(piweb.getTitle()) == null && !piweb.isHidden())
					mapProductItemWEBVisable.put(piweb.getTitle(), piweb);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapProductItemWEBVisable;
	}

Change History

comment:1 Changed 10 years ago by liaojunqiang

  • Description modified (diff)
Note: See TracTickets for help on using tickets.