2017年11月14日星期二

spring bean id 和 bean name一样时,谁优先??

查看SimpleAliasRegistry.canonicalName代码

  public String canonicalName(String name)
  {
    String canonicalName = name;
    String resolvedName;
    do
    {
      resolvedName = (String)this.aliasMap.get(canonicalName);//这里找得到别名的,就了别名
      if (resolvedName != null) {
        canonicalName = resolvedName;
      }
    }
    while (resolvedName != null);
    return canonicalName;
  }


可以知道,name优先了。

比如,定义
id=A name=B
id=B name=C

getBean(B)时,得到的是A

2017年6月4日星期日

和js比,py的一点奇怪

写js多了,看一下py,发现一点奇怪,关于闭包的。
js
var m = 1;
function a(){
 m = 2;
 return function(){
  console.log(m);
 } 
}
m = 3
var x = a();
x();
m = 4;
x();
执行,肯定是打印出,2和4。也就是m的全局变量的修改,影响了闭包。 但是py里
m = 1
def a():
    m = 2
    def b():
        print(m)
    return h:
m = 3
x = a()
x()
m = 4
x()
执行,打印出,2和2。也就是m的修改没影响闭包。对于闭包来讲,m=2固定为环境变量了

2017年4月28日星期五

反向代理为何叫反向代理?,这个解释还可以

正向代理时,c通过p请求s,c知道它通过了p,而s不知道存在p(通常情况下)。
反向代理正好反过来了,c请求s,c其实不知道先经过了p,而s恰恰知道请求是由p转送过来。
比如browser,nginx,php-fpm,php-fpm知道请求不是browser直接过来的,是通过某个p过来,虽然不一定知道那个p是nginx,而browser却不知道它的请求是先到了nginx再到php-fpm


作者:龙海滨
链接:https://www.zhihu.com/question/24723688/answer/125808690
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

2017年3月30日星期四

tomcat load application twice

突然出现这个问题,浪费了不少时间,目前用的是
用的是Eclipse 4.2 Juno tomcat7。
下面的设置会导致load两次
导致两次load的条件‘
 Host的appBase如果是wtpwebapps,并且context的path名字不是project的名字。

避免的方法是appBase指定为webapps就可以了。deploy的路径是wtpwebapps。

自然,这也是wtp的bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=125364

This is being address by work for Bug 145834. The location where modules are deployed now defaults to "wtpwebapps" instead of "webapps" for new servers. This setting can be modified in the server editor.  By publishing modules to a directory other than "webapps", autoDeploy being enabled can cause the second copy to be served.

If this is an issue for an existing server, changing the server's deploy path in the server editor will be necessary.  There is a link in the server editor that can be clicked to set the new default deploy path.  Note that the server must be published (i.e. synchronized) with no modules present before this setting can be changed.

Since this is the extent to which this issue will be addressed, I'm marking it FIXED.

2017年2月7日星期二

synchronized vs volatile

http://www.cnblogs.com/soaringEveryday/p/4418604.html

总结就是
一个变量a

如果需要依赖a,再改变a,就需要 synchronized。因为依赖+改变,要原子,必须synchronized。synchronized保证了原子性+可见性。

如果只是改变a,用volatile。这里改变,不包括a=a+1这样的,只能是a=1。volatile能保证可见性。

这里我也想了单纯的赋值比如a=1,汇编执行时是几个语句,查了一下,int的赋值的确是原子,那么如果long呢,是否还可以用volatile来保证可见性?? 虽然不原子了。何时将thread里的变量更新会共享变量区?


但是,神奇的是
http://blog.csdn.net/yuanwofei/article/details/12843591
根据Java规范,对于基本类型的赋值或者返回值操作,是原子操作。但这里的基本数据类型不包括long和double, 因为JVM看到的基本存储单位是32位,而long 和double都要用64位来表示。所以无法在一个时钟周期内完成。

不知是不是真的这样原因,是不是如果我的jvm是64bit,long和double也原子了。


http://blog.csdn.net/zhaifengmin/article/details/46315003
Java中的原子操作包括:
1)除long和double之外的基本类型的赋值操作
2)所有引用reference的赋值操作
3)java.concurrent.Atomic.* 包中所有类的一切操作。

2016年12月14日星期三

一个小问题,console log的 clickable to source code

[%l]不行,只能显示,click点说找不到文件。得在%前加一个空格。折腾。

http://stackoverflow.com/questions/9588580/log4j-in-java-project-displays-wrong-file-when-clicking-on-link-from-conversion

2016年11月29日星期二

firefox是越来越不给力了

突然就慢了,不是说启动慢,是说加一个tab,或者中键滚动慢。不知道是否因为自动升级导致,google了几下

设置了browser.tabs.animate为false,好像起了效果。