`
文章列表
观察者模式是很常用、常见当然也相当重要的一种设计模式,其中主要包括的概念有: 1.Observer(观察者,又具化作ActionListener) 2.Observable(被观察者) 3.Action(观察者所感兴趣的被观察者的行为)   被观察者主动与观察者建立契约关系(添加观察者),观察者本身具有行为发生被告知资格,即拥有行为响应方法,如actionPerformed,下面贴出一段程序:   import java.util.ArrayList; import java.util.Collection; import java.util.List; import jav ...
    You may hear it said that to improve performance, you should avoid synchronization when reading or writing atomic data. This advice is dangerously wrong. While the language specification guarantees that a thread will not see an arbitrary value when reading a field, it does not guarantee that a ...
package myminaclient; import java.net.InetSocketAddress; import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; import org.apache.mina.core.future.ConnectFuture; import org.apache.mina.filter.codec.ProtocolCodecFilter; import org.apache.mina.filter.codec.textline.TextLineCodecFac ...
A final approach to achieving failure atomicity is to perform the operation on a temporary copy of the object and to replace the contents of the object with the temporary copy once the operation is complete. This approach occurs naturally when the computation can be performed more quickly once the ...
// Exception Translation try { // Use lower-level abstraction to do our bidding ... } catch(LowerLevelException e) { throw new HigherLevelException(...); }   // Exception Chaining try { ... // Use lower-level abstraction to do our bidding } catch (LowerLevelException cause) ...
        我系统是Vista Home Basic SP1,内网机器132.159.×.× ,不能ping通我,但是却能调用我机器上发布的WebService,看来ws和ping没有直接联系了?
Terran  SCV  (出场00)SCV, good to go, sir. SCV可以开工了  (Err00)I can't build it, something's in the way. 我没法在这建,有东西挡道  (Err01)I can't build there. 我没法在这建  (Min00)(采矿1)  (Min01)(采矿2)  (闲聊00)Come again, Captain? 队长,再来一遍!  (闲聊01)I'm not readin' you clearly. 我不能听清楚你说什么。  (闲聊02)You ain't from ...
    down的jwchat项目中文网页或js文件后都有Zh.cn后缀,需要将其剔除,产生了需求,一个很小的程序,不时改进,且记聊以把玩。   import java.io.File; public class Test { public static void main(String[] args) { new Test().renameall(new File("directory"), ".Zh_cn"); } public void renameall(File directory, String facto ...
        通过tsung对openfire进行性能测试,单服基本没有问题,包括客户端cluster,可以进行登录,聊天,Presence改变等等一系列,但是如果针对跨域的非同服情况,貌似就无能为力了,以下是普通的tsung.xml实例: <?xml version="1.0"?> <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd"> <tsung loglevel="notice" version="1.0"> ...
        通常,通过接口名来实现内部匿名类时,如果不希望不得不实现之方法造成繁琐的窘境,则须借助抽象类了,大凡都是以DefaultXxx之类的形式标榜于JDK之中: interface Test1 { public abstract void a();//just to test the abstract keyword void b(); void c(); } abstract class Test2 implements Test1 { public void a() { System.out.println("a"); } ...
原文链接:http://hi.baidu.com/jabber/blog/item/4df7e15027171e591038c2d7.html   Presence处理是IM Server的核心,也是一个IM Server最复杂的部分。一个用户的状态发生变化,需要通过服务器自动投递给他所有在线的好友,因此Presence模块实际上等同一个消息处理服务器,可参看以前消息服务器相关文章ActiveMQ性能研究及与memcacheq比较 。 Presence的复杂性体现在: 1. 由于每个用户都有1到多个好友,服务器的处理量被放大。 2. 分布式处理的复杂度,你的好友可能同时分布在n个 ...
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.SwingWorker; public class Test { public static void main(String[] args) { new Test().go(); } public void go() { update(); } public void update() { Task task = new Task(); ...
运行以下程序,看看两者的区别: public class Test { String teststr = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; public static void main(String[] args) { new Test().go(); } public void go() { long start = System.currentTimeMillis(); statement0() ...
http://aleung.blogbus.com/logs/32090434.html 在Java内存模型中,有main memory,每个线程也有自己的memory (例如寄存器)。为了性能,一个线程会在自己的memory中保持要访问的变量的副本。这样就会出现同一个变量在某个瞬间,在一个线程的memory中的值可能与另外一个线程memory中的值,或者main memory中的值不一致的情况。   一个变量声明为volatile,就意味着这个变量是随时会被其他线程修改的,因此不能将它cache在线程memory中。以下例子展现了volatile的作用: publi ...
volatile仅仅能保证变量可见性, 无法保证原子性. volatile的race condition示例: public class TestRaceCondition {     private volatile int i = 0;         public void increase() {        i++;     }     public int getValue() {        return i;     } } 当多线程执行increase方法时, 是否能保证它的值会是线性递增的呢? 答案是否定的. 原因: 这 ...
Global site tag (gtag.js) - Google Analytics