06 2013 档案
摘要:try { // do something} catch (Exception e) {}错误:这里,catch了Exception,但是在catch中什么动作都没做,那么所有的Exception都被“吞”了
阅读全文
摘要:看http://docs.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html了解了一些基本使用,但是发现里面的代码有问题检查了一下,原来是getCurrentThreadId()应该return uniqueNum.get()而不是return uniqueId.get()改写如下:// Each thread has its own 'thread-ID' even if 'uniqueNum' is staticclass UniqueThreadIdGenerator { private stat
阅读全文
摘要:对于一般的type来说,这二者没有区别,对于array和inner type,就有区别了,可以写代码亲测,如下: 1 package simple; 2 3 class Box { 4 class Inner {} 5 } 6 7 public class Foo { 8 public static void main(String[] args) throws Exception { 9 // Ordinary class:10 System.out.println(Box.class.getCanonicalName());11 ...
阅读全文
摘要:原文地址:https://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html推荐另一篇文章:http://www.ibm.com/developerworks/cn/java/j-refs/Some time ago I was interviewing candidates for a Senior Java Engineer position. Among the many questions I asked was "What can you tell me about weak refere
阅读全文
摘要:对于一些singleton class,如果你让其implements Serializable,会导致该class不再是singleton。使用ObjectInputStream.readObject()读取进来之后,如果是多次读取,就会创建多个object,下面的代码可以证明这一点,解决的办法之一就是override一个 method,readResolve() 1 package foo; 2 3 import java.io.FileInputStream; 4 import java.io.FileOutputStream; 5 import java.io.ObjectInput.
阅读全文
摘要:一句话概括:对于某些数据,如果你不想serialize,那么就让之transient,最简单的例子——password,代码如下: 1 class LoggingInfo implements java.io.Serializable 2 { 3 private Date loggingDate = new Date(); 4 private String uid; 5 private transient String pwd; 6 7 LoggingInfo(String user, String password) ...
阅读全文
摘要:google了一些资料,这里整理记录一下:=== Fromwikipedia.org http://en.wikipedia.org/wiki/Callback_(computer_programming)===// 原文中还给了Javascript和C的例子,这里就不贴出来了,google一下就有Definition: Incomputer programming, acallbackis a piece ofexecutable codethat is passed as anargumentto other code, which is expected tocall back(exe.
阅读全文
摘要:http://docs.oracle.com/javase/tutorial/essential/concurrency/starvelive.htmlLivelockA thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, thenlivelockmay result. As with deadlock, livelocked threads are u
阅读全文
摘要:RT.今天搜的,记录下来,给自己补补脑http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it里面有一篇blog,原文地址http://www.javablogging.com/what-is-serialversionuid/What is serialVersionUID?Most people learn aboutserialVersionUIDafter they write their first serializable object (I know I
阅读全文
摘要:今天突然想到,thread会不会也跟Stream之类的Resources类似,start了就要close或者reclaim百度了一下,没搜到什么有价值的东西,果断还是求助google,在stackoverflow.com找到了一个连接,给大家分享一下这篇文章主要谈了为什么Thread.stop()/suspend()/...是deprecated的,以及我们应该使用何种方法去正确地terminate threadshttp://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html简而言之,ter
阅读全文
摘要:右击project->properties->Resource->面板中有Text File Encoding选项,自己选 导入project的时候出现乱码可以选择这个试试,这个跟你的源文件(.java文件)本身的编码有关系,有可能别人用了某某某编辑器使用的编码是GBK,然而你的编辑器使用的编码是UTF-8,这就会导致出现乱码,解决的办法就是把你自己的编辑器的选项中调整为现有源文件的编码。
阅读全文