亚洲欧洲一区二区,亚洲伊人久久大香线蕉结合,久久激情亚洲精品无码?V http://www.tkk7.com/stephen80/category/5942.html軟件架構,saas,戰(zhàn)略管理zh-cnTue, 05 Jan 2010 06:07:23 GMTTue, 05 Jan 2010 06:07:23 GMT60mysql best practicehttp://www.tkk7.com/stephen80/archive/2010/01/05/308270.html西津渡西津渡Tue, 05 Jan 2010 05:38:00 GMThttp://www.tkk7.com/stephen80/archive/2010/01/05/308270.htmlhttp://www.tkk7.com/stephen80/comments/308270.htmlhttp://www.tkk7.com/stephen80/archive/2010/01/05/308270.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/308270.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/308270.html

Myisam is preferred without transaction and little update(delete)

Big than 4G datafile can user Myisam merge table.

InnoDB with auto_increment primary key is preferred.

Few storage process

Guess: 20m records max per table , 500G data max per tablespace , 256 tables per database (may problem)

Use prepared statement and  batch

Optimize Your Queries For the Query Cache

// query cache does NOT work
$r = mysql_query("SELECT username FROM user WHERE signup_date >= CURDATE()");
 
// query cache works!
$today = date("Y-m-d");
$r = mysql_query("SELECT username FROM user WHERE signup_date >= '$today'");

EXPLAIN Your SELECT Queries

LIMIT 1 When Getting a Unique Row

Index and Use Same Column Types for Joins

Do Not ORDER BY RAND()

Avoid SELECT *

t is a good habit to always specify which columns you need when you are doing your SELECT’s.

Use ENUM over VARCHAR

Use NOT NULL If You Can

Store IP Addresses as UNSIGNED INT (?)

Fixed-length (Static) Tables are Faster

Vertical Partitioning

Vertical Partitioning is the act of splitting your table structure in a vertical manner for optimization reasons.

Example 1: You might have a users table that contains home addresses, that do not get read often. You can choose to split your table and store the address info on a separate table. This way your main users table will shrink in size. As you know, smaller tables perform faster.

Example 2: You have a “last_login” field in your table. It updates every time a user logs in to the website. But every update on a table causes the query cache for that table to be flushed. You can put that field into another table to keep updates to your users table to a minimum.

But you also need to make sure you don’t constantly need to join these 2 tables after the partitioning or you might actually suffer performance decline.

Split the Big DELETE or INSERT Queries

If you have some kind of maintenance script that needs to delete large numbers of rows, just use the LIMIT clause to do it in smaller batches to avoid this congestion.

Smaller Columns Are Faster

Use an Object Relational Mapper

f you do not need the time component, use DATE instead of DATETIME.

Consider horizontally spitting many-columned tables if they contain a lot of NULLs or rarely used columns.

Be an SQL programmer who thinks in sets, not procedural programming paradigms

InnoDB can’t optimize SELECT COUNT(*) queries. Use counter tables! That’s how to scale InnoDB.

Prefer MM with hive

refer :

http://blog.tuvinh.com/top-20-mysql-best-practices/



西津渡 2010-01-05 13:38 發(fā)表評論
]]>
mysql jdbc driver code browserhttp://www.tkk7.com/stephen80/archive/2009/12/30/307741.html西津渡西津渡Wed, 30 Dec 2009 04:41:00 GMThttp://www.tkk7.com/stephen80/archive/2009/12/30/307741.htmlhttp://www.tkk7.com/stephen80/comments/307741.htmlhttp://www.tkk7.com/stephen80/archive/2009/12/30/307741.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/307741.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/307741.html 從時序圖中可以看到,createNewIO()就是新建了一個com.mysql.jdbc.MysqlIO,利用 com.mysql.jdbc.StandardSocketFactory來創(chuàng)建一個socket。然后就由這個mySqlIO來與MySql服務器進行握手(doHandshake()),這個doHandshake主要用來初始化與Mysql server的連接,負責登陸服務器和處理連接錯誤。在其中會分析所連接的mysql server的版本,根據(jù)不同的版本以及是否使用SSL加密數(shù)據(jù)都有不同的處理方式,并把要傳輸給數(shù)據(jù)庫server的數(shù)據(jù)都放在一個叫做packet的 buffer中,調(diào)用send()方法往outputStream中寫入要發(fā)送的數(shù)據(jù)。


useServerPreparedStmts置為true的話,mysql驅(qū)動可以通過PreparedStatement的子類ServerPreparedStatement來實現(xiàn)真正的PreparedStatement的功能




第一位表示數(shù)據(jù)包的開始位置,就是數(shù)據(jù)存放的起始位置,一般都設置為0,就是從第一個位置開始。第二和第三個字節(jié)標識了這個數(shù)據(jù)包的大小,注意的是,這個大小是出去標識的4個字節(jié)的大小,對于非最后一個數(shù)據(jù)包來說,這個大小都是一樣的,就是splitSize,也就是maxThreeBytes,它的值是 255 * 255 * 255。
最后一個字節(jié)中存放的就是數(shù)據(jù)包的編號了,從0開始遞增。
在標識位設置完畢之后,就可以把255 * 255 * 255大小的數(shù)據(jù)從我們準備好的待發(fā)送數(shù)據(jù)包中copy出來了,注意,前4位已經(jīng)是標識位了,所以應該從第五個位置開始copy數(shù)據(jù)

 # packetToSend = compressPacket(headerPacket, HEADER_LENGTH,    
#                 splitSize, HEADER_LENGTH); 

LoadBalancingConnectionProxy
package java.lang.reflect 。 proxy .


http://developer.51cto.com/art/200907/137823.htm

http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-implementation-notes.html

PreparedStatements are implemented by the driver, as MySQL does not have a prepared statement feature. Because of this, the driver does not implement getParameterMetaData() or getMetaData() as it would require the driver to have a complete SQL parser in the client.

Starting with version 3.1.0 MySQL Connector/J, server-side prepared statements and binary-encoded result sets are used when the server supports them.


但這是不是說PreparedStatement沒用呢?不是的,PreparedStatement有其他的好處:
1.代碼的可讀性和可維護性
2.最重要的一點是極大地提高了安全性,可以防止SQL注入

然后我又看了一些網(wǎng)上其他人的經(jīng)驗,基本和我的判斷一致,有兩點要特別提請大家注意:

1.并不是說PreparedStatement在所有的DB上都不會提高效率,PreparedStatement需要服務器端的支持,比如在 Oracle上就會有顯著效果。上面說的測試都是在MySQL上測試的,我找到了一個MySQL架構師的帖子,比較明確地說明了MySQL不支持 PreparedStatement。

2.即便PreparedStatement不能提高性能,在少數(shù)使用時甚至會降低效率,但仍然應該使用PreparedStatement!因為其他好 處實在是太大了!當然,當SQL查詢比較復雜時,可能PreparedStatement好處會更大,只是我沒有測試,不敢肯定。

3.既然PreparedStatement不能提高效率,那PreparedStatement Pool也就沒有必要了。但可以看到每次新建Connection的開銷實在很大,因此Connection Pool絕對必要。





西津渡 2009-12-30 12:41 發(fā)表評論
]]>
java post mortem diagnoshttp://www.tkk7.com/stephen80/archive/2009/12/07/304998.html西津渡西津渡Mon, 07 Dec 2009 06:16:00 GMThttp://www.tkk7.com/stephen80/archive/2009/12/07/304998.htmlhttp://www.tkk7.com/stephen80/comments/304998.htmlhttp://www.tkk7.com/stephen80/archive/2009/12/07/304998.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/304998.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/304998.html jstat -gcutil 16761
jmap -finalizerinfo 16761
jmap -histo 16761
jstack -l 16761
jinfo 16761

Examine the fatal error log file. Default file name is hs_err_pidpid.log in the working-directory.

-XX:+HeapDumpOnOutOfMemoryError
java -agentlib:hprof=heap=dump,format=b application
$ jmap -dump:format=b,file=snapshot.jmap process-pid

1、在jvm啟動時加上:-agentlib:hprof=heap=sites,file=heap.txt  ,然后執(zhí)行一段時間后執(zhí)行 kill -3 <pid>,就可以獲取jvm的內(nèi)存鏡像。類似的通過-agentlib:hprof=cpu=samples,file=cpu.txt查 看cpu的狀況。

http://java.sun.com/javase/6/webnotes/trouble/other/matrix6-Unix.html


Quick Troubleshooting Tips on Solaris OS and Linux for Java SE 6

This "Quick Start Guide" gives you some quick tips for troubleshooting. The subsections list some typical functions that can help you in troubleshooting, including one or more ways to get the information or perform the action.

These tips are organized as follows:

Hung, Deadlocked, or Looping Process
Post-mortem Diagnostics, Memory Leaks
Monitoring
Actions on a Remote Debug Server
Other Functions

Hung, Deadlocked, or Looping Process

  • Print thread stack for all Java threads:
    • Control-"
    • kill -QUIT pid
    • jstack pid (or jstack -F pid if jstack pid does not respond)
  • Detect deadlocks:
    • Request deadlock detection: JConsole tool, Threads tab
    • Print information on deadlocked threads: Control-"
    • Print list of concurrent locks owned by each thread: -XX:+PrintConcurrentLocks set, then Control-"
    • Print lock information for a process: jstack -l pid
  • Get a heap histogram for a process:
    • Start Java process with -XX:+PrintClassHistogram, then Control-"
    • jmap -histo pid (with -F option if pid does not respond)
  • Dump Java heap for a process in binary format to file:
    • jmap -dump:format=b,file=filename pid (with -F option if pid does not respond)
  • Print shared object mappings for a process:
    • jmap pid
  • Print heap summary for a process:
    • Control-"
    • jmap -heap pid
  • Print finalization information for a process:
    • jmap -finalizerinfo pid
  • Attach the command-line debugger to a process:
    • jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=pid

Post-mortem Diagnostics, Memory Leaks

  • Examine the fatal error log file. Default file name is hs_err_pidpid.log in the working-directory.
  • Create a heap dump:
    • Start the application with HPROF enabled: java -agentlib:hprof=file=file,format=b application; then Control-"
    • Start the application with HPROF enabled: java -agentlib:hprof=heap=dump application
    • JConsole tool, MBeans tab
    • Start VM with -XX:+HeapDumpOnOutOfMemoryError; if OutOfMemoryError is thrown, VM generates a heap dump.
  • Browse Java heap dump:
    • jhat heap-dump-file
  • Dump Java heap from core file in binary format to a file:
    • jmap -dump:format=b,file=filename corefile
  • Get a heap histogram for a process:
    • Start Java process with -XX:+PrintClassHistogram, then Control-"
    • jmap -histo pid (with -F option if pid does not respond)
  • Get a heap histogram from a core file:
    • jmap -histo corefile
  • Print shared object mappings from a core file:
    • jmap corefile
  • Print heap summary from a core file:
    • jmap -heap corefile
  • Print finalization information from a core file:
    • jmap -finalizerinfo corefile
  • Print Java configuration information from a core file:
    • jinfo corefile
  • Print thread trace from a core file:
    • jstack corefile
  • Print lock information from a core file:
    • jstack -l corefile
  • Attach the command-line debugger to a core file on the same machine:
    • jdb -connect sun.jvm.hotspot.jdi.SACoreAttachingConnector:javaExecutable=path,core=corefile
  • Attach the command-line debugger to a core file on a different machine:
    • On the machine with the core file: jsadebugd path corefile
      and on the machine with the debugger: jdb -connect sun.jvm.hotspot.jdi.SADebugServerAttachingConnector:debugServerName=machine
  • libumem can be used to debug memory leaks.

Monitoring

Note: The vmID argument for the jstat command is the virtual machine identifier. See the jstat man page for a detailed explanation.

  • Print statistics on the class loader:
    • jstat -class vmID
  • Print statistics on the compiler:
    • Compiler behavior: jstat -compiler vmID
    • Compilation method statistics: jstat -printcompilation vmID
  • Print statistics on garbage collection:
    • Summary of statistics: jstat -gcutil vmID
    • Summary of statistics, with causes: jstat -gccause vmID
    • Behavior of the gc heap: jstat -gc vmID
    • Capacities of all the generations: jstat -gccapacity vmID
    • Behavior of the new generation: jstat -gcnew vmID
    • Capacity of the new generation: jstat -gcnewcapacity vmID
    • Behavior of the old and permanent generations: jstat -gcold vmID
    • Capacity of the old generation: jstat -gcoldcapacity vmID
    • Capacity of the permanent generation: jstat -gcpermcapacity vmID
  • Monitor objects awaiting finalization:
    • JConsole tool, VM Summary tab
    • jmap -finalizerinfo pid
    • getObjectPendingFinalizationCount method in java.lang.management.MemoryMXBean class
  • Monitor memory:
    • Heap allocation profiles via HPROF: java -agentlib:hprof=heap=sites
    • JConsole tool, Memory tab
    • Control-" prints generation information.
  • Monitor CPU usage:
    • By thread stack: java -agentlib:hprof=cpu=samples application
    • By method: java -agentlib:hprof=cpu=times application
    • JConsole tool, Overview and VM Summary tabs
  • Monitor thread activity:
    • JConsole tool, Threads tab
  • Monitor class activity:
    • JConsole tool, Classes tab

Actions on a Remote Debug Server

First, attach the debug daemon jsadebugd, then execute the command:

  • Dump Java heap in binary format to a file: jmap -dump:format=b,file=filename hostID
  • Print shared object mappings: jmap hostID
  • Print heap summary : jmap -heap hostID
  • Print finalization information : jmap -finalizerinfo hostID
  • Print lock information : jstack -l hostID
  • Print thread trace : jstack hostID
  • Print Java configuration information: jinfo hostID

Other Functions

  • Interface with the instrumented Java virtual machines:
    • Monitor for the creation and termination of instrumented VMs: jstatd daemon
    • List the instrumented VMs: jps
    • Provide interface between remote monitoring tools and local VMs: jstatd daemon
    • Request garbage collection: JConsole tool, Memory tab
  • Print Java configuration information from a running process:
    • jinfo pid
  • Dynamically set, unset, or change the value of certain Java VM flags for a process:
    • jinfo -flag flag
  • Print command-line flags passed to the VM:
    • jinfo -flags
  • Print Java system properties:
    • jinfo -sysprops
  • Pass a Java VM flag to the virtual machine:
    • jconsole -Jflag ...
    • jhat -Jflag ...
    • jmap -Jflag ...
  • Print statistics of permanent generation of Java heap, by class loader:
    • jmap -permstat
  • Report on monitor contention.
    • java -agentlib:hprof=monitor=y application
  • Evaluate or execute a script in interactive or batch mode:
    • jrunscript
  • Interface dynamically with an MBean, via JConsole tool, MBean tab:
    • Show tree structure.
    • Set an attribute value.
    • Invoke an operation.
    • Subscribe to notification.
  • Run interactive command-line debugger:
    • Launch a new VM for the class: jdb class
    • Attach debugger to a running VM: jdb -attach address
    http://www.tkk7.com/justinchen/archive/2009/01/08/248738.html


西津渡 2009-12-07 14:16 發(fā)表評論
]]>
java performance http://www.tkk7.com/stephen80/archive/2009/07/22/287892.html西津渡西津渡Wed, 22 Jul 2009 10:07:00 GMThttp://www.tkk7.com/stephen80/archive/2009/07/22/287892.htmlhttp://www.tkk7.com/stephen80/comments/287892.htmlhttp://www.tkk7.com/stephen80/archive/2009/07/22/287892.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/287892.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/287892.html
1. first think algorithm before concurrent
2. first solve top problem
3. memory can be problem with huge data processing
4.  not to use refletion frequently
5. prefering strategy that can optimize both cpu and memory .

technical
1. thread synchronizing is how to queuing
   be sure to use "while(!Thread.currentThread.isInterupted())

2. prefer high level  synchronizing facility to low level methodology such as await,notify

3. dedicated sorter is much faster


 










西津渡 2009-07-22 18:07 發(fā)表評論
]]>
幾個性能的注意點http://www.tkk7.com/stephen80/archive/2007/09/26/148247.html西津渡西津渡Wed, 26 Sep 2007 02:59:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/26/148247.htmlhttp://www.tkk7.com/stephen80/comments/148247.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/26/148247.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/148247.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/148247.html http://www.xker.com/edu/dev/104/0652109570034579.html

十二、不要在循環(huán)中調(diào)用synchronized(同步)方法


方法的同步需要消耗相當大的資料,在一個循環(huán)中調(diào)用它絕對不是一個好主意。

例子:
import java.util.Vector;
public class SYN {
    public synchronized void method (Object o) {
    }
    private void test () {
        for (int i = 0; i < vector.size(); i++) {
            method (vector.elementAt(i));    // violation
        }
    }
    private Vector vector = new Vector (5, 5);
}

更正:
不要在循環(huán)體中調(diào)用同步方法,如果必須同步的話,推薦以下方式:
import java.util.Vector;
public class SYN {
    public void method (Object o) {
    }
private void test () {
    synchronized{//在一個同步塊中執(zhí)行非同步方法
            for (int i = 0; i < vector.size(); i++) {
                method (vector.elementAt(i));   
            }
        }
    }
    private Vector vector = new Vector (5, 5);
}


十三、將try/catch塊移出循環(huán)


把try/catch塊放入循環(huán)體內(nèi),會極大的影響性能,如果編譯JIT被關閉或者你所使用的是一個不帶JIT的JVM,性能會將下降21%之多!
         
例子:         
import java.io.FileInputStream;
public class TRY {
    void method (FileInputStream fis) {
        for (int i = 0; i < size; i++) {
            try {                                      // violation
                _sum += fis.read();
            } catch (Exception e) {}
        }
    }
    private int _sum;
}
         
更正:         
將try/catch塊移出循環(huán)         
    void method (FileInputStream fis) {
        try {
            for (int i = 0; i < size; i++) {
                _sum += fis.read();
            }
        } catch (Exception e) {}
    }
         
參考資料:
Peter Haggar: "Practical Java - Programming Language Guide".
Addison Wesley, 2000, pp.81 – 83


十九、不要在循環(huán)體中實例化變量


在循環(huán)體中實例化臨時變量將會增加內(nèi)存消耗

例子:         
import java.util.Vector;
public class LOOP {
    void method (Vector v) {
        for (int i=0;i < v.size();i++) {
            Object o = new Object();
            o = v.elementAt(i);
        }
    }
}
         
更正:         
在循環(huán)體外定義變量,并反復使用         
import java.util.Vector;
public class LOOP {
    void method (Vector v) {
        Object o;
        for (int i=0;i<v.size();i++) {
            o = v.elementAt(i);
        }
    }
}

二十一、盡可能的使用棧變量


如果一個變量需要經(jīng)常訪問,那么你就需要考慮這個變量的作用域了。static? local?還是實例變量?訪問靜態(tài)變量和實例變量將會比訪問局部變量多耗費2-3個時鐘周期。
         
例子:
public class USV {
    void getSum (int[] values) {
        for (int i=0; i < value.length; i++) {
            _sum += value[i];           // violation.
        }
    }
    void getSum2 (int[] values) {
        for (int i=0; i < value.length; i++) {
            _staticSum += value[i];
        }
    }
    private int _sum;
    private static int _staticSum;
}     
         
更正:         
如果可能,請使用局部變量作為你經(jīng)常訪問的變量。
你可以按下面的方法來修改getSum()方法:         
void getSum (int[] values) {
    int sum = _sum;  // temporary local variable.
    for (int i=0; i < value.length; i++) {
        sum += value[i];
    }
    _sum = sum;
}
         
參考資料:         
Peter Haggar: "Practical Java - Programming Language Guide".
Addison Wesley, 2000, pp.122 – 125





西津渡 2007-09-26 10:59 發(fā)表評論
]]>
大量字符串操作中的性能問題http://www.tkk7.com/stephen80/archive/2007/09/26/148224.html西津渡西津渡Wed, 26 Sep 2007 02:14:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/26/148224.htmlhttp://www.tkk7.com/stephen80/comments/148224.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/26/148224.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/148224.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/148224.html
1). 簡單的認為 .append() 效率好于 "+" 是錯誤的!
    2). 不要使用 new 創(chuàng)建 String
    3). 注意 .intern() 的使用
    4). 在編譯期能夠確定字符串值的情況下,使用"+"效率最高
    5). 避免使用 "+=" 來構造字符串
    6). 在聲明StringBuffer對象的時候,指定合適的capacity,不要使用默認值(18)
    7). 注意以下二者的區(qū)別不一樣
        - String s = "a" + "b";
        - String s = "a";
          s += "b";

關鍵點
1. 無論何時只要可能的話使用字符串字面量來常見字符串而不是使用new關鍵字來創(chuàng)建字符串。
2. 無論何時當你要使用new關鍵字來創(chuàng)建很多內(nèi)容重復的字符串的話,請使用String.intern()方法。
3. +操作符會為字符串連接提供最佳的性能――當字符串是在編譯期決定的時候。
4. 如果字符串在運行期決定,使用一個合適的初期容量值初始化的StringBuffer會為字符串連接提供最佳的性能。



西津渡 2007-09-26 10:14 發(fā)表評論
]]>
重歸簡約http://www.tkk7.com/stephen80/archive/2007/09/14/145158.html西津渡西津渡Fri, 14 Sep 2007 07:52:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/14/145158.htmlhttp://www.tkk7.com/stephen80/comments/145158.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/14/145158.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/145158.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/145158.html

castor, dwr, acegi, 幾乎扔掉。

spring ,hibernate 也只用在適當?shù)膱龊稀?br />
struts2 ,也只用在適當?shù)膱龊稀?br />

一些偷懶的技術,盡量避免。
opensession in view.



西津渡 2007-09-14 15:52 發(fā)表評論
]]>
重新評估 solrhttp://www.tkk7.com/stephen80/archive/2007/09/07/143491.html西津渡西津渡Fri, 07 Sep 2007 09:18:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/07/143491.htmlhttp://www.tkk7.com/stephen80/comments/143491.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/07/143491.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/143491.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/143491.html一直困擾于 indexSearcher 的重新 new ,query filter 的cache 沒了。 重讀solr ,發(fā)現(xiàn)非常好。也許我應該考慮用 solr 了。


Caching

  • Configurable Query Result, Filter, and Document cache instances
  • Pluggable Cache implementations
  • Cache warming in background
    • When a new searcher is opened, configurable searches are run against it in order to warm it up to avoid slow first hits. During warming, the current searcher handles live requests.
  • Autowarming in background
    • The most recently accessed items in the caches of the current searcher are re-populated in the new searcher, enabing high cache hit rates across index/searcher changes.
  • Fast/small filter implementation
  • User level caching with autowarming support
9-26
  今天,我發(fā)現(xiàn),我可以用不同的方式實現(xiàn)cache ,也許在我的情況下比solr 的方式更好。


西津渡 2007-09-07 17:18 發(fā)表評論
]]>
關于j2ee 性能的一個課題http://www.tkk7.com/stephen80/archive/2007/09/06/143275.html西津渡西津渡Thu, 06 Sep 2007 12:55:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/06/143275.htmlhttp://www.tkk7.com/stephen80/comments/143275.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/06/143275.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/143275.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/143275.html 開源軟件,用什么樣的 proxy, cache, web container 達到最好的性能。

瓶頸在于:
 tomcat 只能用到2g ram

經(jīng)過研究,
xmx 在windows 2003,jdk1.5.06 ,1999M.
所以如果是一臺單純的web container server 就不要搞8G了, 1U 的4G ok.

需要用到那么高的性能場景,只能是兩臺1U做 banlance.

再次研究
用 session stick ,balance 2 個 tomcat ,應該可以達到較好的性能。



西津渡 2007-09-06 20:55 發(fā)表評論
]]>
c3p0 ,hibernate 配置,springhttp://www.tkk7.com/stephen80/archive/2007/09/06/143150.html西津渡西津渡Thu, 06 Sep 2007 05:16:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/06/143150.htmlhttp://www.tkk7.com/stephen80/comments/143150.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/06/143150.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/143150.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/143150.html

spring+hibernate
   
連接池

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  
    
     <property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/openfire"/>
<property name="user" value="root"/>
<property name="password" value="password"/>
   
    </bean>
   
   
</beans>

tomcat jndi:

<Resource auth="Container" description="DB Connection" driverClass="com.mysql.jdbc.Driver" maxPoolSize="4" minPoolSize="2" acquireIncrement="1" name="jdbc/TestDB" user="test" password="ready2go" factory="org.apache.naming.factory.BeanFactory" type="com.mchange.v2.c3p0.ComboPooledDataSource" jdbcUrl="jdbc:mysql://localhost:3306/test?autoReconnect=true" />






建議:c3p0.propertyies

c3p0.acquireIncrement=5       
c3p0.idleConnectionTestPeriod=1800   
c3p0.initialPoolSize=5       
c3p0.maxIdleTime=1000
c3p0.maxPoolSize=20   
c3p0.maxStatements=100   
c3p0.minPoolSize=5


just hibernate:
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider


調(diào)優(yōu):在我的環(huán)境下
maxpoolSize 30, 1822 , 15, 1655 。 可能和測試過程有關。
maxStatement 加上, 3600。嚴重影響性能。

擴大 xms xmx 512 ,957




西津渡 2007-09-06 13:16 發(fā)表評論
]]>
tree ,hibernate, db hierarchical http://www.tkk7.com/stephen80/archive/2007/09/05/142887.html西津渡西津渡Wed, 05 Sep 2007 06:18:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/05/142887.htmlhttp://www.tkk7.com/stephen80/comments/142887.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/05/142887.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/142887.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/142887.html
有些操作,在db 中更好。

1。取得所有的葉子節(jié)點。

SELECT Name FROM Projects p WHERE NOT EXISTS( SELECT * FROM Projects WHERE Parent=p.VertexId)

2。multilevel operation ,用數(shù)據(jù)庫的輔助表, 用triger 。
CREATE TABLE ProjectPaths(

VertexId INTEGER,

Depth INTEGER,

Path VARCHAR(300) 。



)
3. 用 hibernate 時,如果 stack over flow,考慮用 stack 代替recursive algrithm

public void traverseDepthFirst( AST ast )
{
// Root AST node cannot be null or
// traversal of its subtree is impossible.
if ( ast == null )
{
throw new IllegalArgumentException(
"node to traverse cannot be null!" );
}
// Map to hold parents of each
// AST node. Unfortunately the AST
// interface does not provide a method
// for finding the parent of a node, so
// we use the Map to save them.

Map parentNodes = new HashMap();

// Start tree traversal with first child
// of the specified root AST node.

AST currentNode = ast.getFirstChild();

// Remember parent of first child.

parentNodes.put( currentNode , ast );

// Iterate through nodes, simulating
// recursive tree traversal, and add them
// to queue in proper order for later
// linear traversal. This "flattens" the
// into a linear list of nodes which can
// be visited non-recursively.

while ( currentNode != null )
{
// Visit the current node.

strategy.visit( currentNode );

// Move down to current node's first child
// if it exists.

AST childNode = currentNode.getFirstChild();

// If the child is not null, make it
// the current node.

if ( childNode != null )
{
// Remember parent of the child.

parentNodes.put( childNode , currentNode );

// Make child the current node.

currentNode = childNode;

continue;
}

while ( currentNode != null )
{
// Move to next sibling if any.

AST siblingNode = currentNode.getNextSibling();

if ( siblingNode != null )
{
// Get current node's parent.
// This is also the parent of the
// sibling node.

AST parentNode = (AST)parentNodes.get( currentNode );

// Remember parent of sibling.

parentNodes.put( siblingNode , parentNode );

// Make sibling the current node.

currentNode = siblingNode;

break;
}
// Move up to parent if no sibling.
// If parent is root node, we're done.

currentNode = (AST)parentNodes.get( currentNode );

if ( currentNode.equals( ast ) )
{
currentNode = null;
}
}
}




參考:

http://wordhoard.northwestern.edu/userman/hibernatechanges.html

《Tansact Sql cookbook.》








西津渡 2007-09-05 14:18 發(fā)表評論
]]>
hibernate 的幾個注意點http://www.tkk7.com/stephen80/archive/2007/09/05/142860.html西津渡西津渡Wed, 05 Sep 2007 04:11:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/05/142860.htmlhttp://www.tkk7.com/stephen80/comments/142860.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/05/142860.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/142860.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/142860.html
private List _items;

<bag
name="items"
inverse="true"   //盡量使用雙向關聯(lián)
order-by="DATE_TIME"
cascade="all">
<key column="BLOG_ID"/>
<one-to-many class="BlogItem"/>
</bag>


many-to-many ,建議用 set



二、one-to-one 適用
            通過主鍵進行關聯(lián)
            相當于把大表拆分為多個小表
            例如把大字段單獨拆分出來,以提高數(shù)據(jù)庫操作的性能

三、composite element ,必須依賴的導航關系

 <list name="lineItems" table="line_items">
<key column="order_id"/>
<list-index column="line_number"/>
<composite-element class="LineItem">
<property name="quantity"/>
<many-to-one name="product" column="product_id"/>
</composite-element>
</list>

四、 one-one formula , 很復雜,有點不明白

 <class name="Person">
<id name="name"/>
<one-to-one name="address"
cascade="all">
<formula>name</formula>
<formula>'HOME'</formula>
</one-to-one>
<one-to-one name="mailingAddress"
cascade="all">
<formula>name</formula>
<formula>'MAILING'</formula>
</one-to-one>
</class>
<class name="Address" batch-size="2"
check="addressType in ('MAILING', 'HOME', 'BUSINESS')">
<composite-id>
<key-many-to-one name="person"
column="personName"/>
<key-property name="type"
column="addressType"/>
</composite-id>
<property name="street" type="text"/>
<property name="state"/>
<property name="zip"/>
</class>


五、繼承關系, per subclass table ,no discriminator ,joined-subclass




六、tree
拷貝: http://www.thogau.net/tutorials/tree/tutorial02-01.jsp


package net.thogau.website.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * This class implements a persisted tree node.
 *
 * @author <a href="mailto:thogau@thogau.net">thogau</a>
 *
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.class table="node"
 */
public class Node extends BaseObject implements Serializable {
   
    // mapped to primary key in node table
    protected Long id;
       
    protected String name;
   
    protected Node parent = null;
   
    protected List children = new ArrayList();
   
    /**
     * @hibernate.id column="id" generator-class="native" unsaved-value="null"
     * @struts.form-field
     */
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }   
   
    /**
     * Returns the node name.
     *
     * @return String
     *
     * @hibernate.property column="name" not-null="true" unique="true"
     * @struts.form-field
     * @struts.validator type="required"
     *
     */
    public String getName() {
        return name;
    }  
    public void setName(String name) {
        this.name = name;
    }
   
    /**
     * Returns the node's children.
     *
     * @return List
     *
     * @hibernate.list cascade="all-delete-orphan" inverse="true"
     * @hibernate.collection-one-to-many class="net.thogau.website.model.Node"
     * @hibernate.collection-index column="position"
     * @hibernate.collection-key column="parent_id"
     * @struts.form-field
     */
    public List getChildren() {
        return children;
    }

    public void setChildren(List children) {
        this.children = children;
    }
   
    /**
     * Returns the position of the node in the children list (if it has parent).
     * @return int
     *
     * @hibernate.property column="position"
     */   
    public int getPosition() {
        try{
            return parent.getChildren().indexOf(this);
        }
        catch(NullPointerException e){
            // if it has no parent, position makes no sense
            return -1;
        }
    }
   
    public void setPosition(int position) { /* not used */ }
   
    /**
     * Returns the node's parent.
     *
     * @return Node
     *
     * @hibernate.many-to-one column = "parent_id" class="net.thogau.website.model.Node" cascade = "none"
     * @hibernate.column name="parent_id"
     */
     public Node getParent() {
        return parent;
    }
    
    public void setParent(Node n) {
        this.parent = n;
    }
   
    /**
     * @see java.lang.Object#equals(Object)
     */
    public boolean equals(Object object) {
        if (!(object instanceof Node)) {
            return false;
        }
        Node rhs = (Node) object;
        return new EqualsBuilder().append(this.name, rhs.name).append(
                this.children, rhs.children).append(this.parent, rhs.parent)
                .append(this.id, rhs.id).isEquals();
    }
   
    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return new HashCodeBuilder(1036586079, -537109207).append(this.name)
                .append(this.parent.getName()).append(this.id)
                .toHashCode();
    }
   
    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("name", this.name).append("parent", this.parent)
                .append("id", this.id).append("position", this.getPosition()).toString();
    }
   
}

好像,equal ,hash 是必須的。

# /**
#      * 樹形遍歷
#      * 不用遞歸,用堆棧.
#      * 這里只是做為例子,本人不建議把業(yè)務邏輯封裝在Entity層.
#                 */ 
#     public List getVisitResults() { 
#         List l = new ArrayList(); 
#         Stack s = new Stack(); 
#         s.push(this); 
#         while (s.empty() == false) { 
#            Cat c = (Cat) s.pop(); 
#            l.add(c); 
#            List children = c.getChildren(); 
#               if (children != null) { 
#                  for (int i = 0; i <  hildren.size(); i++)   { 
#             Cat cat = (Cat) children.get(i); 
#             s.push(cat); 
#                  }//end for 
#              }//end if 
#         }//end while 
#         return l; 
#     } 






 









西津渡 2007-09-05 12:11 發(fā)表評論
]]>
lucene 的index 更新http://www.tkk7.com/stephen80/archive/2007/09/04/142612.html西津渡西津渡Tue, 04 Sep 2007 06:00:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/04/142612.htmlhttp://www.tkk7.com/stephen80/comments/142612.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/04/142612.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/142612.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/142612.html 所以,重新開 searcher 的頻率對于很重的訪問量來說,不能太頻繁。這樣查詢肯定有不能同步的問題。

對于不要求同步的場景來說,夠了。
繼續(xù)研究。







西津渡 2007-09-04 14:00 發(fā)表評論
]]>
solr 部署http://www.tkk7.com/stephen80/archive/2007/09/04/142611.html西津渡西津渡Tue, 04 Sep 2007 05:53:00 GMThttp://www.tkk7.com/stephen80/archive/2007/09/04/142611.htmlhttp://www.tkk7.com/stephen80/comments/142611.htmlhttp://www.tkk7.com/stephen80/archive/2007/09/04/142611.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/142611.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/142611.html
jndi solr/home :

<Context docBase="D:\sourcecode\apache-solr\dist\solr.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="D:\sourcecode\solr-sample\solr" override="true" />
</Context>

solr/home 的結構
conf
data/index



西津渡 2007-09-04 13:53 發(fā)表評論
]]>
struts2 ognl 與 jsp2.1 el 的沖突問題http://www.tkk7.com/stephen80/archive/2007/08/29/140988.html西津渡西津渡Wed, 29 Aug 2007 09:00:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/29/140988.htmlhttp://www.tkk7.com/stephen80/comments/140988.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/29/140988.html#Feedback1http://www.tkk7.com/stephen80/comments/commentRss/140988.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/140988.html由于 nio 帶來的性能提升,tomcat6 不能被忽略。

辦法1:

http://www.devzuz.org/blogs/bporter/2006/08/05/1154706744655.html

<ww:select list="#{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" />

改用-------------------------------------------------------------
<ww:select list="#@java.util.HashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" />

這樣 jsp2.1 el 就不會有問題了。

辦法2: 對于舊的程序,不愿意改了,可以向后兼容
http://today.java.net/lpt/a/272#backwards-compatibility

必須用 Servlet 2.5 XSD.
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<jsp-property-group>
<deferred-syntax-allowed-as-literal>
true
</deferred-syntax-allowed-as-literal>


</jsp-property-group>
或者在頁面中
<%@page  language="java" deferredSyntaxAllowedAsLiteral="true" %>

辦法3 :不用 jsp2.1 el

> <jsp-config>
> <jsp-property-group>
> <url-pattern>*.jsp</url-pattern>
> <el-ignored>true</el-ignored>
> </jsp-property-group>
> </jsp-config>

http://www.mail-archive.com/dev@struts.apache.org/msg28920.html
我現(xiàn)在的疑問
在一個頁面中采用兩個 el 引擎,是否會對性能造成一定影響?
較小。



















西津渡 2007-08-29 17:00 發(fā)表評論
]]>
mod_cache http://www.tkk7.com/stephen80/archive/2007/08/27/140067.html西津渡西津渡Mon, 27 Aug 2007 09:44:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/140067.htmlhttp://www.tkk7.com/stephen80/comments/140067.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/140067.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/140067.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/140067.htmlLoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so

<IfModule mod_cache.c>
    <IfModule mod_mem_cache.c>
        CacheEnable mem /images
    CacheEnable mem /styles
    CacheEnable mem /scripts

        MCacheSize 10240
        MCacheMaxObjectCount 100
        MCacheMinObjectSize 1
        MCacheMaxObjectSize 2048
    </IfModule>
  
</IfModule>



西津渡 2007-08-27 17:44 發(fā)表評論
]]>
apach mod_http_proxy ,mod_rewrite 一起工作http://www.tkk7.com/stephen80/archive/2007/08/27/140029.html西津渡西津渡Mon, 27 Aug 2007 08:48:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/140029.htmlhttp://www.tkk7.com/stephen80/comments/140029.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/140029.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/140029.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/140029.html
<VirtualHost *:80>
 

RewriteLogLevel 3
RewriteLog "f:/temp/logs/lelerewrite.log"
RewriteEngine    on
RewriteRule    ^(.*)\.html$    http://www.lele.com/ [P]

 ProxyPass /images !
ProxyPass /styles !
ProxyPass /scripts !
  
 
  ProxyPass / http://localhost:8082/
 ProxyPassReverse / http://localhost:8082/
 ServerName www.lele.com:8082


 CustomLog logs/lele_access.log common

DocumentRoot "D:/apachedocroot/www.lele.com/"

 

<Directory />

    Options FollowSymLinks
    AllowOverride None
 
    Order allow,deny
    Allow from all


</Directory>


</VirtualHost>

一 、tomcat 中要配置:<connector ,proxy ,> .否則返回有問題。
二、 mod_proxy_ajp 在 apr 情況下性能應該比 mod_http_proxy 好。





西津渡 2007-08-27 16:48 發(fā)表評論
]]>
apache access log,關閉缺省http://www.tkk7.com/stephen80/archive/2007/08/27/139995.html西津渡西津渡Mon, 27 Aug 2007 08:13:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/139995.htmlhttp://www.tkk7.com/stephen80/comments/139995.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/139995.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/139995.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/139995.html #customLog logs/access.log common

在 virtualhost 中加
  CustomLog logs/lele_access.log common



西津渡 2007-08-27 16:13 發(fā)表評論
]]>
apache mod_rewritehttp://www.tkk7.com/stephen80/archive/2007/08/27/139910.html西津渡西津渡Mon, 27 Aug 2007 06:19:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/139910.htmlhttp://www.tkk7.com/stephen80/comments/139910.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/139910.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/139910.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/139910.html
在 <virtualHost> 中

RewriteLogLevel 3
RewriteLog "f:/temp/logs/sosorewrite.log"
RewriteEngine    on
RewriteRule    ^(.*)\.html$    /index.php


西津渡 2007-08-27 14:19 發(fā)表評論
]]>
用 apache mod_proxy_ajp 與 tomcat 集成, 很簡單的步驟http://www.tkk7.com/stephen80/archive/2007/08/27/139846.html西津渡西津渡Mon, 27 Aug 2007 03:59:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/139846.htmlhttp://www.tkk7.com/stephen80/comments/139846.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/139846.html#Feedback1http://www.tkk7.com/stephen80/comments/commentRss/139846.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/139846.html  loadmodule mod_proxy
 loadmobule mod_proxy_ajp
 
 增加
 ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>


<VirtualHost *:80>
 
 ProxyPass /images !
ProxyPass /styles !
ProxyPass /scripts !
  
 ProxyPass / ajp://localhost:8009/
 ProxyPassReverse / ajp://localhost:8009/  
 ServerName www.lele.com:8082


 CustomLog logs/lele_access.log common

DocumentRoot "D:/apachedocroot/www.lele.com/"

 

<Directory />

    Options FollowSymLinks
    AllowOverride None
 
    Order allow,deny
    Allow from all


</Directory>


</VirtualHost>

tomcat 不用做修改。
安裝 tomcat apr, 性能會比較好。






西津渡 2007-08-27 11:59 發(fā)表評論
]]>
學習配置 apache 虛擬主機http://www.tkk7.com/stephen80/archive/2007/08/27/139823.html西津渡西津渡Mon, 27 Aug 2007 03:12:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/27/139823.htmlhttp://www.tkk7.com/stephen80/comments/139823.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/27/139823.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/139823.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/139823.html
Listen 80

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot "D:/apachedocroot/www.soso.com/"
ServerName www.soso.com


<Directory />

    Options FollowSymLinks
    AllowOverride None
 
    Order allow,deny
    Allow from all

</Directory>


</VirtualHost>

<VirtualHost *:80>

DocumentRoot "D:/apachedocroot/static.soso.com/"
ServerName static.soso.com

<Directory />

    Options FollowSymLinks
    AllowOverride None
 
    Order allow,deny
    Allow from all

</Directory>

</VirtualHost>

二、修改 hosts 文件
三、 httpd.ext -S 測試配置




西津渡 2007-08-27 11:12 發(fā)表評論
]]>
j2ee 員學習 配置 apache2.2.4 php 5.2.3http://www.tkk7.com/stephen80/archive/2007/08/24/139174.html西津渡西津渡Fri, 24 Aug 2007 12:46:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/24/139174.htmlhttp://www.tkk7.com/stephen80/comments/139174.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/24/139174.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/139174.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/139174.html
配置 apache2.2.4 ,php 5.2.3.

1. 解壓到 c:\php
2. 拷貝 php.ini-dist 到 c:\windows 為 php.ini
    ** 不能用recommend**
3. 拷貝 php5ts.dll 到 c:\windows\system32

配置:apache ,http.conf
1. LoadModule php5_module "c:/php/php5apache2_2.dll"
    ** 對應apache2.2 必須用這個**
2. AddType application/x-httpd-php  .php
3. if module dir_modle ,
    DirectoryIndex  index.php ,index.html

配置php.ini ,啟動 mysql
extension=php_mysql.dll
extension=php_mysqli.dll

測試
phpinfo.php

<? echo phpinfo(); ?>

ok.



西津渡 2007-08-24 20:46 發(fā)表評論
]]>
Mediator 設計模式http://www.tkk7.com/stephen80/archive/2007/08/07/134998.html西津渡西津渡Tue, 07 Aug 2007 08:43:00 GMThttp://www.tkk7.com/stephen80/archive/2007/08/07/134998.htmlhttp://www.tkk7.com/stephen80/comments/134998.htmlhttp://www.tkk7.com/stephen80/archive/2007/08/07/134998.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/134998.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/134998.html就是兩個人之間要溝通,不是直接,而是通過 mediator.
也就是 ,不是
        user1.sendMessage(user2,"some message");
       而是
        user1.getMediator().sendMessage("user2","some message");

 有什么好處呢:
        職責分離:mediator 完成自己該承擔的職責。
        mediator 也可以搞這搞那。

插一段實際代碼:
      conn.getChatManager().createChat("thewho@stephenli",new MessageListener() {

            public void processMessage(Chat chat, Message message) {
               
                if(logger.isDebugEnabled())
                logger.debug("Received message: " + message.toXML());
               
            }
        }).sendMessage("測試發(fā)送!");


下面是junit 一段別人的代碼,可以Run:

代碼看起來很蠢,不能說明使用mediator 的好處。不過意思就是這樣啦!(從C# 拷的)


import junit.framework.TestCase;


public class MediatorTest extends TestCase {
   
    public void testMediator(){
        Mediator m = new Mediator();
        DataProviderColleague c1 = new DataProviderColleague(m);
        DataConsumerColleague c2 = new DataConsumerColleague();
        m.IntroduceColleagues(c1,c2);

        c1.ChangeData();
       
    }
}



    class Mediator
    {
        private DataProviderColleague dataProvider;
        private DataConsumerColleague dataConsumer;
        public void IntroduceColleagues(DataProviderColleague c1, DataConsumerColleague c2)
        {
            dataProvider = c1;
            dataConsumer = c2;           
        }
       
        public void DataChanged()
        {
            int i = dataProvider.getIMyData();
            dataConsumer.NewValue(i);
        }
    }

    class DataConsumerColleague
    {
        public void NewValue(int i)
        {
            System.out.println("New value "+ i);
        }
    }

    class DataProviderColleague
    {
        private Mediator mediator;
        private int iMyData=0;
        private int MyData ;
   
        public DataProviderColleague(Mediator m)
        {
            mediator = m;
        }

        public void ChangeData()
        {
            iMyData = 403;

            // Inform mediator that I have changed the data
            if (mediator != null)
                mediator.DataChanged();   
        }

        public int getIMyData() {
            return iMyData;
        }

        public void setIMyData(int myData) {
            iMyData = myData;
        }       
       
       
       
    }

 















西津渡 2007-08-07 16:43 發(fā)表評論
]]>
推薦一篇 StAX and WoodStox 的介紹文章,英文http://www.tkk7.com/stephen80/archive/2007/07/23/131820.html西津渡西津渡Mon, 23 Jul 2007 02:36:00 GMThttp://www.tkk7.com/stephen80/archive/2007/07/23/131820.html StAX the odds with Woodstox


剛讀了,感覺不錯。

Over a decade into XML evolution, however, these parsing technologies are slowly showing their age, requiring bypasses and optimizations to overcome their well-known limitations. StAX, or Streaming API for XML, is the new-age XML parser that offers the best features of the existing models, and at the same time provides high performance and efficient access to the underlyi  閱讀全文

西津渡 2007-07-23 10:36 發(fā)表評論
]]>
規(guī)劃一下能力提高的步驟http://www.tkk7.com/stephen80/archive/2007/07/13/130116.html西津渡西津渡Fri, 13 Jul 2007 08:25:00 GMThttp://www.tkk7.com/stephen80/archive/2007/07/13/130116.htmlhttp://www.tkk7.com/stephen80/comments/130116.htmlhttp://www.tkk7.com/stephen80/archive/2007/07/13/130116.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/130116.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/130116.html1.rick  client 的全面掌握
  以前用dwr ,再復習一下  . ok ,prototypes . 07-08-01
2.db procedure
  以前基本不會。
3.ejb3
  高可靠性transaction
4. StAX, woodstox
   學習一下新的xml 處理技術。 ok.  07-08-01
5.REST
   新東西,很重要    .         ok. 07-08-1
6.english






西津渡 2007-07-13 16:25 發(fā)表評論
]]>
接口優(yōu)于繼承,組合優(yōu)于繼承http://www.tkk7.com/stephen80/archive/2006/07/21/59410.html西津渡西津渡Fri, 21 Jul 2006 06:05:00 GMThttp://www.tkk7.com/stephen80/archive/2006/07/21/59410.htmlhttp://www.tkk7.com/stephen80/comments/59410.htmlhttp://www.tkk7.com/stephen80/archive/2006/07/21/59410.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/59410.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/59410.html看來堅持面向interface 的開發(fā)是必須的了。
問題在
? Abstract class 不能復雜,我想這也是template pattern 時候要注意的。
? template 要穩(wěn)定,不確定的東西不能放在template 中,當然簡單的東西容易穩(wěn)定。
?
?否則必然違背 ocp 原則。


西津渡 2006-07-21 14:05 發(fā)表評論
]]>
htmlparser 的裝死問題http://www.tkk7.com/stephen80/archive/2006/07/21/59408.html西津渡西津渡Fri, 21 Jul 2006 06:00:00 GMThttp://www.tkk7.com/stephen80/archive/2006/07/21/59408.htmlhttp://www.tkk7.com/stephen80/comments/59408.htmlhttp://www.tkk7.com/stephen80/archive/2006/07/21/59408.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/59408.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/59408.htmlhtmlParser 會裝死。
我想只能加一個monitor thread ,不過沒有完成。


西津渡 2006-07-21 14:00 發(fā)表評論
]]>
htmlParser 遇到的encoding 問題http://www.tkk7.com/stephen80/archive/2006/07/21/59407.html西津渡西津渡Fri, 21 Jul 2006 05:58:00 GMThttp://www.tkk7.com/stephen80/archive/2006/07/21/59407.htmlhttp://www.tkk7.com/stephen80/comments/59407.htmlhttp://www.tkk7.com/stephen80/archive/2006/07/21/59407.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/59407.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/59407.html??? 問題在于 頁面的charset=gb2312 ,而 頁面中有gbk 的碼 ,比如 'fb9c'.
??? 代碼可以驗證,
? ? ??? byte[] gbchar = new byte[2];
??? ??? gbchar[0]=(byte) 0xfb;
??? ??? gbchar[1]=(byte) 0x9c;
??? ??? System.out.print(new String(gbchar,"gbk"));
??? ??? System.out.print(new String(gbchar,"gb2312"));

??? 不過,我并沒有解決這個問題。



西津渡 2006-07-21 13:58 發(fā)表評論
]]>
webalizer 作點擊量統(tǒng)計http://www.tkk7.com/stephen80/archive/2006/04/30/44228.html西津渡西津渡Sun, 30 Apr 2006 08:33:00 GMThttp://www.tkk7.com/stephen80/archive/2006/04/30/44228.htmlhttp://www.tkk7.com/stephen80/comments/44228.htmlhttp://www.tkk7.com/stephen80/archive/2006/04/30/44228.html#Feedback1http://www.tkk7.com/stephen80/comments/commentRss/44228.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/44228.html

西津渡 2006-04-30 16:33 發(fā)表評論
]]>
用clickStream 做業(yè)務日志http://www.tkk7.com/stephen80/archive/2006/04/30/44227.html西津渡西津渡Sun, 30 Apr 2006 08:31:00 GMThttp://www.tkk7.com/stephen80/archive/2006/04/30/44227.htmlhttp://www.tkk7.com/stephen80/comments/44227.htmlhttp://www.tkk7.com/stephen80/archive/2006/04/30/44227.html#Feedback0http://www.tkk7.com/stephen80/comments/commentRss/44227.htmlhttp://www.tkk7.com/stephen80/services/trackbacks/44227.html

西津渡 2006-04-30 16:31 發(fā)表評論
]]>
主站蜘蛛池模板: 亚洲国产一区二区视频网站| 亚洲人成影院在线| 久久国产一片免费观看| 亚洲人成网www| 在线视频免费观看www动漫| 青青草国产免费国产是公开| 亚洲第一精品福利| 免费视频中文字幕| 国产午夜成人免费看片无遮挡| 日本亚洲精品色婷婷在线影院| 亚洲国产精品一区二区第一页免| 免费A级毛片av无码| 亚洲av最新在线观看网址| 日本红怡院亚洲红怡院最新| 亚洲精品视频久久| 在线日韩av永久免费观看| 免费精品久久天干天干| 中文字幕在线观看亚洲日韩| 亚洲宅男天堂在线观看无病毒| 免费高清小黄站在线观看| 99久久久国产精品免费牛牛四川 | 亚洲av无码av在线播放| 久久精品国产亚洲AV麻豆王友容| 午夜成年女人毛片免费观看| 国产午夜不卡AV免费| 国产午夜亚洲精品不卡| 亚洲视频国产精品| 国产gv天堂亚洲国产gv刚刚碰| 成年人免费观看视频网站| 久草免费手机视频| 免费无码专区毛片高潮喷水| 久久精品国产99国产精品亚洲| 国产精品免费观看| 中文在线免费视频| 国产亚洲精品2021自在线| 亚洲国产高清美女在线观看 | 亚洲精品乱码久久久久久按摩| 国产网站免费观看| 国产精品成人免费一区二区| 一级毛片免费观看不卡视频| 亚洲an日韩专区在线|