Google AdSense for Search

Google
 

Google Referrals

Tuesday, December 08, 2009

track back I'm beta testing Maxis FTTH! - CNET Asia Blogs PopTech for You by Alan Tan, Malaysia.

was trying to find back the article regarding the fiber connection that i read before.

found by phrase: malaysia fiber connection lucky

Tuesday, July 28, 2009

KK trip on web (selected photos)

Tuesday, June 23, 2009

Synchronized在java的用法

2009-05-12 13:41
Java 对多线程的支持与同步机制深受大家的喜爱,似乎看起来使用了synchronized关键字就可以轻松地解决多线程共享数据同步问题。

到底如何?――还得对synchronized关键字的作用进行深入了解才可定论。 总的说来,synchronized关键字可以作为函数的修饰符,也可作为函数内的语句,也就是平时说的同步方法和同步语句块。

如果再细的分类,synchronized可作用于
  • instance变量、
  • object reference(对象引用)、
  • static函数 和
  • class literals(类名称字面常量)身上。
在进一步阐述之前,我们需要明确几点:
  1. 无论synchronized关键字加在方法上还是对象上,它取得的锁都是对象,而不是把一段代码或函数当作锁――而且同步方法很可能还会被其他线程的对象访问。
  2. 每个对象只有一个锁(lock)与之相关联。
  3. 实现同步是要很大的系统开销作为代价的,甚至可能造成死锁,所以尽量避免无谓的同步控制。 接着来讨论synchronized用到不同地方对代码产生的影响: 假设P1、P2是同一个类的不同对象,这个类中定义了以下几种情况的同步块或同步方法,P1、P2就都可以调用它们。
  • 把synchronized当作函数修饰符时,示例代码如下: Public synchronized void methodAAA() { //…. } 这也就是同步方法,那这时synchronized锁定的是哪个对象呢?它锁定的是调用这个同步方法对象。也就是说,当一个对象P1在不同的线程中执行这个同步方法时,它们之间会形成互斥,达到同步的效果。但是这个对象所属的Class所产生的另一对象P2却可以任意调用这个被加了synchronized关键字的方法。 上边的示例代码等同于如下代码: public void methodAAA() { synchronized (this) // (1) { //….. } } (1)处的this指的是什么呢?它指的就是调用这个方法的对象,如P1。可见同步方法实质是将synchronized作用于object reference。――那个拿到了P1对象锁的线程,才可以调用P1的同步方法,而对P2而言,P1这个锁与它毫不相干,程序也可能在这种情形下摆脱同步机制的控制,造成数据混乱:(
  • 同步块,示例代码如下: public void method3(SomeObject so) { synchronized(so) { //….. } } 这时,锁就是so这个对象,谁拿到这个锁谁就可以运行它所控制的那段代码。当有一个明确的对象作为锁时,就可以这样写程序,但当没有明确的对象作为锁,只是想让一段代码同步时,可以创建一个特殊的instance变量(它得是一个对象)来充当锁: class Foo implements Runnable { private byte[] lock = new byte[0]; // 特殊的instance变量 Public void methodA() { synchronized(lock) { //… } } //….. } 注:零长度的byte数组对象创建起来将比任何对象都经济――查看编译后的字节码:生成零长度的byte[]对象只需3条操作码,而Object lock = new Object()则需要7行操作码。 3.将synchronized作用于static 函数,示例代码如下: Class Foo { public synchronized static void methodAAA() // 同步的static 函数 { //…. } public void methodBBB() { synchronized(Foo.class) // class literal(类名称字面常量) } } 代码中的methodBBB()方法是把class literal作为锁的情况,它和同步的static函数产生的效果是一样的,取得的锁很特别,是当前调用这个方法的对象所属的类(Class,而不再是由这个Class产生的某个具体对象了)。 记得在《Effective Java》一书中看到过将 Foo.class和 P1.getClass()用于作同步锁还不一样,不能用P1.getClass()来达到锁这个Class的目的。P1指的是由Foo类产生的对象。 可以推断:如果一个类中定义了一个synchronized的static函数A,也定义了一个synchronized 的instance函数B,那么这个类的同一对象Obj在多线程中分别访问A和B两个方法时,不会构成同步,因为它们的锁都不一样。A方法的锁是Obj这个对象,而B的锁是Obj所属的那个Class。 小结如下: 搞清楚synchronized锁定的是哪个对象,就能帮助我们设计更安全的多线程程序。

还有一些技巧可以让我们对共享资源的同步访问更加安全:
  1. 定义private 的instance变量+它的 get方法,而不要定义public/protected的instance变量。如果将变量定义为public,对象在外界可以绕过同步方法的控制而直接取得它,并改动它。这也是JavaBean的标准实现方式之一。
  2. 如果instance变量是一个对象,如数组或ArrayList什么的,那上述方法仍然不安全,因为当外界对象通过get方法拿到这个instance对象的引用后,又将其指向另一个对象,那么这个private变量也就变了,岂不是很危险。 这个时候就需要将get方法也加上synchronized同步,并且,只返回这个private对象的clone()――这样,调用端得到的就是对象副本的引用了。

Friday, June 19, 2009

P1 service after sales...

SMS received from 62003 on 2009 June 18, Thursday 10:59pm:

P1 is experiencing temporary service interruption that affects some of our subscribers. Affected users may experience limited to no service during this period. Our tech team is working to restore service to its full capacity. We will provide further updates as and when available. Thanks.

but the line was facing problem to get the connection since evening right 5/7 hours before i receive this sms... is this better than some service provider?

which only to tell u when u call to their answering machine...

彩色兵马俑

Pictures source from: http://jianghua9161.blog.sohu.com/114969895.html





:
转图(快载):http://2su.de/Er (picasaweb.google.com)
原图(慢载):http://2su.de/VfM (Chinese Version)

兵马俑中英文介绍 (Chinese / English version)

24年等待彩色兵马俑方阵出土 (Chinese Version)

秦始皇兵马俑时隔24年今日第三次发掘(图) (Chinese Version)

江蘇出土彩色漢兵馬俑 (Chinese Version)

出土彩色木俑比兵马俑早500年 (Chinese Version)

Friday, May 15, 2009

Struts - multiple message-resources

source from: http://viralpatel.net/blogs/2008/11/multiple-message-resource-property-file-in-struts.html

Multiple message resource property file in Struts



Make an entry of message resource file name in struts-config.xml file.





Once this is done, the message resource file can be accessed by using the key (in this case we have myResource & myOtherResource). The key should be used in tag in jsp to display perticular message from the resource property file. bundle=”" attribute of is used to identify the perticular property file.


key="somekey.in.myresource" />
key="somekey.in.myotherresource"/>

Tuesday, May 05, 2009

TTplayer 5.5 beta, i love it

what i love TTplayer 5.5 beta:

  • application in utf-8 encoding.
  • 重命名文件 (个别、批件式) (single or batch file rename)
  • 2b continue...

Monday, May 04, 2009

Web Application - MVC Layers

source found: http://www.javapassion.com/strutscodecamp/

Three Logical Layers in a Web Application: Model, View, Control
? Model (Business process layer)
– Models the data and behavior behind the business process
– Responsible for actually doing
? Performing DB queries
? Calculating the business process
? Processing orders
– Encapsulate of data and behavior which are independent of presentation
? View (Presentation layer)
– Display information according to client types
– Display result of business logic (Model)
– Not concerned with how the information was obtained, or from where (since that is the responsibility of Model)
? Controller (Control layer)
– Serves as the logical connection between the user's interaction and the business services on the back
– Responsible for making decisions among multiple presentations
? e.g. User's language, locale or access level dictates a different presentation.
– A request enters the application through the control layer, it will decide how the request should be handled and what information should be returned

Web Applications

  • It is often advantageous to treat each layer as an independent portion of your application
  • Do not confuse logical separation of responsibilities with actual separation of components
  • Some or of the layers can be combined into single components to reduce application complexity

what's the different of these???

  • logical separation of responsibilities
  • actual separation of components