我来证明dwr的application 是线程不安全的

欢迎大家一起讨论扔砖


我就在网上简单搜了搜, 没找到关于其application的线程安全权威说法

自己看源码吧。。。


扫了一眼javax.servlet.ServletContext的层次结构如下

第二个MockServletContext是个静态内部类

其setAttribute方法居然这样,直接不考虑了

 
      public void setAttribute(String s, Object obj)
       {
       }


剩下org.directwebremoting.util.FakeServletContext了


其setAttribute方法如下:


    public void setAttribute(String name, Object value)
    {
        if(value != null)
            attributes.put(name, value);
        else
            attributes.remove(name);
    }




追加写入一个org.directwebremoting.util.FakeServletContext  其attributes 属性如下:


private final Map attributes;


attributes实例

public FakeServletContext(String resourceBasePath) {
		initParameters = new Properties();
		attributes = new HashMap();
		servletContextName = "FakeServletContext";
		this.resourceBasePath = resourceBasePath == null ? ""
				: resourceBasePath;
		String tempDir = System.getProperty("java.io.tmpdir");
		if (tempDir != null)
			attributes.put("javax.servlet.context.tempdir", new File(tempDir));
	}



显而易见了。。。。。

当然这是我所找到的实现,其他实现可能有所不同,至少Dwr的这个是不安全的,但是还有很多 实现 是线程安全的




猜你喜欢

转载自ldbjakyo.iteye.com/blog/746245