2008年12月31日星期三

blogger daily 12/31/2008


Posted from Diigo. The rest of my favorite links are here.

2008年12月23日星期二

blogger daily 12/23/2008


Posted from Diigo. The rest of my favorite links are here.

2008年12月14日星期日

blogger daily 12/14/2008


Posted from Diigo. The rest of my favorite links are here.

2008年12月6日星期六

2008年12月5日星期五

2008年12月4日星期四

blogger daily 12/04/2008


Posted from Diigo. The rest of my favorite links are here.

2008年12月2日星期二

blogger daily 12/02/2008


Posted from Diigo. The rest of my favorite links are here.

2008年12月1日星期一

使用jps查看java进程ID

在Linux上经常需要查看Java的进程ID,例如想kill掉某个Java进程就需要pid。使用ps + grep可能觉得不是很方便,如果classpath很长,输出会非常难看。
其实从JDK1.5开始,Sun就提供了一个非常方便的Java进程查看工具:jps 。 配合适当的参数,输出一目了然。例如,我经常使用jps -lv,
-l
Output the full package name for the application's main class or the full path name to the application's JAR file.
-v
Output the arguments passed to the JVM.

更多的参数可以查看jdk的文档http://java.sun.com/javase/6/docs/technotes/tools/share/jps.html

JDK提供这个工具是为了和其他的Troubleshooting工具配合使用,例如jmap、jstack,这些工具也很有意思,有兴趣的可以尝试用用http://java.sun.com/javase/6/docs/technotes/tools/index.html#troubleshoot。

blogger daily 12/01/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月28日星期五

blogger daily 11/28/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月27日星期四

如何让手机和Google calendar同步

Google calendar是一个非常优秀的服务,方便的操作界面,支持多个日历,多种的通知方式,我一直在使用它。自从用了智能手机,我就非常希望手机的日程安排能和Google calendar同步,这样,我就能同时在手机和Google calendar上更新日程,而不用担心信息的不一致。Google了一下,发现了这个网站,正好能满足我的要求。


注册后,仔细看了一下,竟然不支持我的Windows Mobile,晕倒。只好再去Google。后来找到了一条曲线救国的道路。

Google calendar提供了一个小软件Google Calendar Sync,支持calendar和Outlook的同步,而我的手机也可以和Outlook同步,于是通过Outlook,打通了手机和calendar之间的道路。麻烦虽然是麻烦一点,但我喜欢:)

blogger daily 11/27/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月26日星期三

blogger daily 11/26/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月25日星期二

2008年11月23日星期日

blogger daily 11/23/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月22日星期六

2008年11月20日星期四

blogger daily 11/20/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月19日星期三

blogger daily 11/19/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月18日星期二

blogger daily 11/18/2008


Posted from Diigo. The rest of my favorite links are here.

2008年11月16日星期日

保俶塔



Java Concurrency in Practice

JavaConcurrency in Practice

几位Java大牛的作品,绝对值得一读!

下载

Threads are a fundamental part of the Javaplatform. As multicore processors become the norm, usingconcurrency effectively becomes essential for buildinghigh-performance applications. Java SE 5 and 6 are a huge stepforward for the development of concurrent applications, withimprovements to the Java Virtual Machine to supporthigh-performance, highly scalable concurrent classes and a rich setof new concurrency building blocks. In Java Concurrency inPractice, the creators of these new facilitiesexplain not only how they work and how to use them, but also themotivation and design patterns behind them.
However, developing, testing, and debuggingmultithreaded programs can still be very difficult; it is all tooeasy to create concurrent programs that appear to work, but failwhen it matters most: in production, under heavy load. Java Concurrency inPractice arms readers with both the theoreticalunderpinnings and concrete techniques for building reliable,scalable, maintainable concurrent applications. Rather than simplyoffering an inventory of concurrency APIs and mechanisms, itprovides design rules, patterns, and mental models that make iteasier to build concurrent programs that are both correct andperformant.
This book covers:
  • Basic concepts of concurrency and threadsafety
  • Techniques for building and composingthread-safe classes
  • Using the concurrency building blocks injava.util.concurrent
  • Performance optimization dos and don'ts
  • Testing concurrent programs
  • Advanced topics such as atomic variables,nonblocking algorithms, and the Java Memory Model

代码大全(第二版)

 代码大全(第二版)

C++ Primer (3RD)中文版

C++ Primer (3RD)中文版

(一本久负盛名的C++经典教程)



下载

2008年10月9日星期四

2008年8月4日星期一

links for 2008-08-03 [delicious.com]

2008年6月18日星期三

Effective Java (2nd Edition)

经过几年的积淀,Effective Java 终于出第二版了!

2008年6月16日星期一

how to package a jar including its dependencies

使用maven的时候,想生成jar,并且包含项目依赖的components,可以使用shade plugin,简单又方便。

 
<build>

   
<plugins>

     
<plugin>

       
<artifactId>maven-shade-plugin</artifactId>

       
<version>1.0.1</version>

       
<executions>

         
<execution>

           
<phase>package</phase>

           
<goals>

             
<goal>shade</goal>

           
</goals>            

         
</execution>

       
</executions>

     
</plugin>

   
</plugins>

 
</build>

2008年6月2日星期一

如何减少Berkeley DB Log File占用磁盘的空间

我的应用程序在缺省配置的情况下,5百多万条记录,Log File占用了532M的硬盘空间。仔细看了下文档,发现Berkeley DB日志文件占用的空间,有很大的弹性。Berkeley DB一直会以append的方式增加log文件,同时有clean log thread负责清理无用的log。为了更高的程序性能,Berkeley DB会根据参数的配置,允许已经失效的log存在于log file中,这样可以减少cleanLog thread和其他thread锁的竞争。而我希望提高log file的利用率,减少log占用的硬盘空间,并且能够容忍这样做带来的性能损失。因此修改了je.properties,定义je.cleaner.minUtilization为90(缺省为50),同时在关闭environment的时候,强制执行cleanLog:

    boolean anyCleaned = false;
        while (dbenv.cleanLog() > 0) {
            anyCleaned = true;
        }
        if (anyCleaned) {
            CheckpointConfig force = new CheckpointConfig();
            force.setForce(true);
            dbenv.checkpoint(force);
        }

调整后,log file占用的空间下降为309M,效果非常明显。
je.properties

# maximum starting size of a JE log buffer
# 32M
je.log.bufferSize=33554432

# The number of JE log buffers
# minimum = 2
je.log.numBuffers=2

# The total memory taken by log buffers, in bytes. If 0, use
# 7% of je.maxMemory
# minimum = 6144
# 32M * 2
je.log.totalBufferBytes=67108864

# By default, JE sizes the cache as a percentage of the maximum
# memory available to the JVM. For example, if the JVM is
# started with -Xmx128M, the cache size will be
#           (je.maxMemoryPercent * 128M) / 100
# Setting je.maxMemory to an non-zero value will override
# je.maxMemoryPercent
# minimum = 1
# maximum = 90
je.maxMemoryPercent=80

# If true (the default), use an LRU-only policy to select nodes for
# eviction.  If false, select by Btree level first, and then by LRU.
je.evictor.lruOnly=false

# The number of nodes in one evictor scan
# minimum = 1
# maximum = 1000
je.evictor.nodesPerScan=100

# The cleaner will keep the total disk space utilization percentage
# above this value. The default is set to 50 percent.
# minimum = 0
# maximum = 90
je.cleaner.minUtilization=90

2008年5月26日星期一

Berkeley DB Java Edition performance tuning

为了统计2亿5千万个词的三元词组的出现频率,想了很多办法。三元组对象占用内存40bytes,计数器占用的内存16bytes,那么,光是2亿5千万个三元组,大约就要占用13G的空间,考虑到归并的情况,最少也要6G空间。

感觉最合适的应该是采用MapReduce计算模型,并行完成这么大数据量的计算。目前唯一开源的MapReduce项目是Hadoop,但我要真正用起来还没有条件,目前只有两台PC,而且都装的是Windows系统。但Hadoop绝对是应该重点研究的对象,因为今后要处理的是更加大的数据量。

Terracotta也考察了一下,本以为它可以联合多个PC作为一个能存储海量数据的distributed Hash Map,但Terracotta只是通过一个中心的server去协调多个节点来share数据,如果数据量很大,它会在server上persist data to disk。它使用的是Berkeley DB 作为 persistent layer。我不需要在多个node之间share数据,那还不如直接用Berkeley DB。

接着就是试用Berkeley DB,在没有任何优化的情况下,效率很低。虽然我给JVM开了1G的内存,但观察到程序运行时,内存使用增长非常的缓慢,马上就意识到应该加大buffer size,不要让I/O这么频繁。翻了一下文档,设置了如下的je.properties:
# If true (default is false) NIO is used for all file I/O.
je.log.useNIO=true

# If non-0 (default is 0) break all IO into chunks of this size.
# This setting is only used if je.log.useNIO=true.
# minimum = 0
# maximum = 67108864
je.log.chunkedNIO=8192

# If true (default is false) direct NIO buffers are used.
# This setting is only used if je.log.useNIO=true.
je.log.directNIO=true

# The maximum size of each individual JE log file, in bytes.
# minimum = 1000000
# maximum = 4294967296
# 100M
je.log.fileMax=104857600

# maximum starting size of a JE log buffer
# 32M
je.log.bufferSize=33554432

# The number of JE log buffers
# minimum = 2
je.log.numBuffers=2

# The total memory taken by log buffers, in bytes. If 0, use
# 7% of je.maxMemory
# minimum = 6144
# 32M * 2
je.log.totalBufferBytes=67108864

# By default, JE sizes the cache as a percentage of the maximum
# memory available to the JVM. For example, if the JVM is
# started with -Xmx128M, the cache size will be
#           (je.maxMemoryPercent * 128M) / 100
# Setting je.maxMemory to an non-zero value will override
# je.maxMemoryPercent
# minimum = 1
# maximum = 90
je.maxMemoryPercent=60

# If true (the default), use an LRU-only policy to select nodes for
# eviction.  If false, select by Btree level first, and then by LRU.
je.evictor.lruOnly=false

# The number of nodes in one evictor scan
# minimum = 1
# maximum = 1000
je.evictor.nodesPerScan=100


打开NIO,关掉LRU cache management policy(http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#35)。把buffer size加到了32M。运行效率有了质的提升,1个小时处理了一千多万个词。但随后的处理速度又明显的下降了。根据Jconsole观察的结果,似乎把cache设置的过大,导致Heap memory大部分都被cache占据。于是又把maxMemoryPercent降到了60%,运行程序,回家走人,等着周一看结果。谁知道周日下午得知,公司周末停电了。faint。看来下周还要重新运行,但起码现在有了一点阶段性的成果。记录之。

2008年5月21日星期三

terracotta开发notes

1. 安装erlipse插件,生成terracotta项目
2. 选择root object
3. 对共享对象的访问加锁
4. 选择需要共享的对象
5. 可以参考TC_INSTALL_DIR/docs/tc-config-reference.xml,手工修改后,将tc-config.xml上传到运行terracotta的服务器
6. 使用 start-tc-server.sh -f ../conf/tc-config.xml 启动服务器
7. 编辑客户端脚本,一般的模式如下
   set TC_INSTALL_DIR=C:\javaapp\terracotta\
     set TC_CONFIG_PATH=ip:port
   set DSO_BOOT_JAR=%~d0%~p0dso-boot-hotspot_win32_150_12.jar

   call %TC_INSTALL_DIR%\bin\dso-env.bat -q

   set JAVA_OPTS=%TC_JAVA_OPTS% %JAVA_OPTS%
 
   java %JAVA_OPTS% -Xmx512M xxx
8. 运行客户端

2008年5月18日星期日

How to run the OpenSSH SSHD server on Windows using Cygwin

How to run the OpenSSH SSHD server on Windows using Cygwin
How to setup automatic login with ssh without a password

1. Install the following Cygwin packages (rerun setup if necessary -- you can add packages after you have already installed Cygwin).

   Admin --> cygrunsrv
   Net --> openssh

2. Open a new bash shell window and run the SSH configure stuff.

   ssh-host-config

   注意,在配置过程中,UsePrivilegeSeparation选择no。这样,sshd不会启动单独的线程,后面我们就有机会手工修改sshd_config。

3. Now you are ready to start the service.

   cygrunsrv -S sshd

   stop
   
   cygrunsrv -E sshd

4. Generate your key pair using the following command:
   $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

5. $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

6. 修改/etc/sshd_config,使sshd能够使用到上一步生成的authorized_keys
   AuthorizedKeysFile    .ssh/authorized_keys

tips:
如何查看sshd服务器端的log信息
1. 修改/etc/sshd_config,打开LogLevel,并改为DEBUG。
2. 日志要通过administrative tools->Event Viewer查看,属于application log。

ssh -v 查看登录过程中的debug信息

http://www.noah.org/wiki/Sshd_on_Windows
http://magicmonster.com/kb/net/ssh/auto_login.html

2008年5月16日星期五

eclipse plug-in

Eclipse-cs Checkstyle (http://eclipse-cs.sourceforge.net/update/)
EasyExplore 1.0.4 (http://sourceforge.net/projects/easystruts/)

import checkstyle & fomatter configuration

使用cygwin,.bashrc不能生效问题的解决

安装了cygwin后,为了使ls列出文件目录时能有颜色,需要在/etc/bash.bashrc或~/.bashrc中加入下面的命令:
alias ls='ls -F -N --color=auto'
如果想立即生效,可以执行
source /etc/bash.bashrc。
但我退出后再进入,总是不能生效,google了一下,发现可以在home目录下的.bash_profile中加入同样的语句。
试了一下,这回行了,希望对遇到同样问题的人有点帮助。

2008年4月17日星期四

2008年4月16日星期三

XML process Tips

1. how to determine the character encoding of a feed

这个功能由com.sun.syndication.io.XmlReader完成

http://wiki.java.net/bin/view/Javawsxml/Rome05CharsetEncoding

http://diveintomark.org/archives/2004/02/13/xml-media-types



2. what is xml BOM?

字符编码详解:http://blog.csdn.net/hillMover/archive/2005/10/06/496093.aspx



3. rome在处理feed的时候,将html的特殊字符,转换成了xml entity。

 
这个功能是由com.sun.syndication.io.impl.XmlFixerReader完成的,其中定义了一个map,作为映射。

 
CODED_ENTITIES.put("&nbsp;",  "&#160;");

 
CODED_ENTITIES.put("&iexcl;", "&#161;");

 
.........



4.

在使用Jdom,把xml输出为String的过程中,需要定义processing instruction to disable output escaping.

org.jdom.output.XMLOutputter.printProcessingInstruction



// IMPORTANT!! set processing instruction to disable output escaping

ProcessingInstruction pi = new ProcessingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "data");

root.addContent(0, pi);



5. 最后,实现一个方法,将xml entities map to html。

  
就是将rome的功能倒过来。

2008年3月10日星期一

2008年1月16日星期三

十万个为什么,中国电信屏蔽Google背后的秘密

今天看到一篇blog,作者猜测了为什么中国电信屏蔽google,其中是这样说的:
中国电信和美国运营商是按照流量进行结算的,中国用户访问美国网站的流量费用最终是由中国电信支付给美国运营商的,中国电信因为发现Google的这些服务带来了大量中国大陆到美国的线路流量,这些流量在这几个月来一直在不断增加,中国电信不愿白白支付这笔越来越多的国际间的电路费用,因此将Google的这几个服务的进行了屏蔽,彻底切断了这些流量。
虽然仅仅是作者的猜测,但鲁迅说过:“不惮以最坏的恶意来推测中国人”。

2008年1月13日星期日

数据库中多表的连接

Inner Joins
An inner join (sometimes called a "simple join") is a join of two or more tables that returns only those rows that satisfy the join condition. Outer Joins
An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.
To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join), use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in the WHERE clause. For all rows in A that have no matching rows in B, Oracle returns null for any select list expressions containing columns of B.

To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join), use the RIGHT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in the join condition in the WHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for any select list expressions containing columns of A.

To write a query that performs an outer join and returns all rows from A and B, extended with nulls if they do not satisfy the join condition (a full outer join), use the FULL [OUTER] JOIN syntax in the FROM clause.

2008年1月10日星期四

拍老虎没送命,拍城管却把命丢了.

在新浪留言里看到的,拍老虎没送命!拍城管却把命丢了!可笑可悲!!结论,城管猛于虎!

男子拍下城管粗暴执法照片 拒绝删除被打死
男子被城管打死续:天门市委书记称天理不容

但我觉得更恶心的是什么市委书记的一段管腔,他说出了一句打粮食的话吗?

别必雄说:“听到这起事件发生,我的心情非常沉重。这个事件是完全不该发生的。无论村民怎么阻拦垃圾清运,组织几十名城管人员到现场与群众斗殴、抖狠,都是不应该的。将途经此地下车拍照的市水利建筑工程公司经理魏文华殴打致死,更是天理不容。”
他说:“对事件的处理要尊重事实,不遮不掩,依法严惩肇事人,决不姑息迁就。对参与的当事人、组织指挥人,无论是谁,无论涉及多少人,都要依法严惩。公安部门要加强与省厅联系汇报,尽快缩短办案时间。检察院要及早介入,纪检、监察部门要抓紧调查”。
他说:“这起事件的发生,暴露了天门市机关作风建设中存在着严重问题。我们要以此事件为反面教材,举一反三,吸取深刻的教训,加强干部队伍的法纪教育,加强干部的作风建设,牢固树立执政为民的理念。”

2008年1月7日星期一

很黄很暴力

不经意间,又创造了一个流行语,一下就把”很好,很强大“比了下去。你想方设法出名,但却不如人家的无心插柳。真的很黄很暴力。

2008年1月2日星期三

华南虎

跨年度的热点新闻,你快要遗忘的时候,他又会蹦出来表示它还活着。可以作为娱乐新闻炒作的范本。