c++ difference from java
1. take charge of object management , negotiate ownershiop ,use scoped_ptr,
not to transfer other's ownership
2. use c++ template to express seperation corncern ,such as (static)polymorphy and policy
3. disable copy constructor and assign operator by yourself
4. polymorphy by pointer
5. 使用 template ,macro 取得類似動(dòng)態(tài)語言的能力
6. 偏好無狀態(tài)的 函數(shù)
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/
從時(shí)序圖中可以看到,createNewIO()就是新建了一個(gè)com.mysql.jdbc.MysqlIO,利用 com.mysql.jdbc.StandardSocketFactory來創(chuàng)建一個(gè)socket。然后就由這個(gè)mySqlIO來與MySql服務(wù)器進(jìn)行握手(doHandshake()),這個(gè)doHandshake主要用來初始化與Mysql server的連接,負(fù)責(zé)登陸服務(wù)器和處理連接錯(cuò)誤。在其中會(huì)分析所連接的mysql server的版本,根據(jù)不同的版本以及是否使用SSL加密數(shù)據(jù)都有不同的處理方式,并把要傳輸給數(shù)據(jù)庫server的數(shù)據(jù)都放在一個(gè)叫做packet的 buffer中,調(diào)用send()方法往outputStream中寫入要發(fā)送的數(shù)據(jù)。
useServerPreparedStmts置為true的話,mysql驅(qū)動(dòng)可以通過PreparedStatement的子類ServerPreparedStatement來實(shí)現(xiàn)真正的PreparedStatement的功能
第一位表示數(shù)據(jù)包的開始位置,就是數(shù)據(jù)存放的起始位置,一般都設(shè)置為0,就是從第一個(gè)位置開始。第二和第三個(gè)字節(jié)標(biāo)識了這個(gè)數(shù)據(jù)包的大小,注意的是,這個(gè)大小是出去標(biāo)識的4個(gè)字節(jié)的大小,對于非最后一個(gè)數(shù)據(jù)包來說,這個(gè)大小都是一樣的,就是splitSize,也就是maxThreeBytes,它的值是 255 * 255 * 255。
最后一個(gè)字節(jié)中存放的就是數(shù)據(jù)包的編號了,從0開始遞增。
在標(biāo)識位設(shè)置完畢之后,就可以把255 * 255 * 255大小的數(shù)據(jù)從我們準(zhǔn)備好的待發(fā)送數(shù)據(jù)包中copy出來了,注意,前4位已經(jīng)是標(biāo)識位了,所以應(yīng)該從第五個(gè)位置開始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.代碼的可讀性和可維護(hù)性
2.最重要的一點(diǎn)是極大地提高了安全性,可以防止SQL注入
然后我又看了一些網(wǎng)上其他人的經(jīng)驗(yàn),基本和我的判斷一致,有兩點(diǎn)要特別提請大家注意:
1.并不是說PreparedStatement在所有的DB上都不會(huì)提高效率,PreparedStatement需要服務(wù)器端的支持,比如在
Oracle上就會(huì)有顯著效果。上面說的測試都是在MySQL上測試的,我找到了一個(gè)MySQL架構(gòu)師的帖子,比較明確地說明了MySQL不支持
PreparedStatement。
2.即便PreparedStatement不能提高性能,在少數(shù)使用時(shí)甚至?xí)档托剩匀粦?yīng)該使用PreparedStatement!因?yàn)槠渌?
處實(shí)在是太大了!當(dāng)然,當(dāng)SQL查詢比較復(fù)雜時(shí),可能PreparedStatement好處會(huì)更大,只是我沒有測試,不敢肯定。
3.既然PreparedStatement不能提高效率,那PreparedStatement Pool也就沒有必要了。但可以看到每次新建Connection的開銷實(shí)在很大,因此Connection Pool絕對必要。
download ,annatation and tools 兩個(gè)項(xiàng)目。
添加相關(guān)的 jar.
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="master.classpath" />
<target name="create_table">
<hibernatetool destdir="${script.dir}">
<annotationconfiguration configurationfile="src/hibernate.cfg.xml" />
<hbm2ddl export="false" create="true" delimiter=";" format="true" outputfilename="create-tables.sql" />
</hibernatetool>
</target>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="logi">
<property name="show_sql">true</property>
<mapping class="com.tt.logi.target.Target"/>
</session-factory>
</hibernate-configuration>
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Target implements Serializable{
private Long id;
private String name;
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Basic
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
wget ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.41.tar.gz
tar -xzf
./configure --prefix=/usr/local/mysql51m --without-debug --enable-local-infile --enable-assembler --enable-thread-safe-client --with-plugins=all
make
su -
make install
groupadd mysql
useradd -g mysql mysql
bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql51m/data
chown -R mysql /var/lib/mysql51m/
chgrp -R mysql /var/lib/mysql51m/
cp share/mysql/my-innodb-heavy-4G.cnf my.cnf
vi my.cnf
datadir = /var/lib/mysql51m/data
.bin/mysqld_safe --defaults-file=/usr/local/mysql51m/my.cnf &
bin/mysql --defaults-file=my.cnf -uroot
./mysqladmin -u root password ‘humber’
grant all on *.* to root@% identified by 'humber'
default-character-set=utf8
init_connect='SET NAMES utf8'
default-storage-engine = INNODB
jmap -heap 16761
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啟動(dòng)時(shí)加上:
-agentlib:hprof=heap=sites,file=heap.txt
,然后執(zhí)行一段時(shí)間后執(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:
- Print heap summary for a process:
- Print finalization information for a process:
- 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:
- 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:
- Print shared object mappings from a core file:
- Print heap summary from a core file:
- Print finalization information from a core file:
- jmap -finalizerinfo corefile
- Print Java configuration information from a core file:
- Print thread trace from a core file:
- Print lock information from a core file:
- 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:
- 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:
- Dynamically set, unset, or change the value of certain Java VM flags for a process:
- Print command-line flags passed to the VM:
- Print Java system properties:
- 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:
- Report on monitor contention.
- java -agentlib:hprof=monitor=y application
- Evaluate or execute a script in interactive or batch mode:
- 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
netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,""t",state[key]}'
set nocompatible
set autoindent
set smartindent
set ignorecase
syntax enable
set wrap
set showmatch
set foldmarker={{{,}}}
set tabstop=4
set shiftwidth=4
set ruler
set expandtab
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set nobackup
setlocal noswapfile
set bufhidden=hide
syntax on
set tags=./tags,~/apsara/tags
set path+=/usr/include/c++/**,~/apsara/include/**
filetype plugin on
filetype indent on
autocmd filetype java,c,cpp setlocal textwidth=100
set pastetoggle=<F7>
nmap <F2> :set nonumber!<CR>
nmap <F8> :TlistToggle<CR>
imap <F11> <C-x><C-p>
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --exclude=build --extra=+q .<CR>
map <F6> :w<CR>
imap <F6> <ESC>:w<CR>a
map <F3> /<C-R><C-W><CR>
有 c support 支持,很棒。
-
避免對shared_ptr所管理的對象的直接內(nèi)存管理操作,以免造成該對象的重釋放
shared_ptr并不能對循環(huán)引用的對象內(nèi)存自動(dòng)管理(這點(diǎn)是其它各種引用計(jì)數(shù)管理內(nèi)存方式的通?。?。
-
不要構(gòu)造一個(gè)臨時(shí)的shared_ptr作為函數(shù)的參數(shù)。
如下列代碼則可能導(dǎo)致內(nèi)存泄漏:
void test()
{
foo(boost::shared_ptr<implementation>(new implementation()),g());
}
正確的用法為:
void test()
{
boost::shared_ptr<implementation> sp (new implementation());
foo(sp,g());
}
-
Employee boss("Morris, Melinda", 83000);
Employee* s = &boss;
This is usually not a good idea. As a rule of thumb, C++ pointers should
only refer to objects allocated wth new.
copy:http://www.diybl.com/course/3_program/c++/cppjs/20090403/163770.html
抄錄備忘:
其實(shí)沒有.h也能很好的工作,但是當(dāng)你發(fā)現(xiàn)一個(gè)外部鏈接的函數(shù)或外部變量,需要許多份
聲明,因?yàn)閏++這種語言,在使用函數(shù)和變量的時(shí)候,必須將他聲明,為何要聲明?聲明之后才
知道他的規(guī)格,才能更好的發(fā)現(xiàn)不和規(guī)格的部分.你別妄想一個(gè)編譯單元,會(huì)自動(dòng)從另一個(gè)
編譯單元那里得到什么信息,知道你是如何定義這個(gè)函數(shù)的.
所以說,只要使用到該函數(shù)的單元,就必須寫一份聲明在那個(gè).cpp里面,這樣是不是很麻煩,
而且,如果要修改,就必須一個(gè)一個(gè)修改.這真讓人受不了.
.h就是為了解決這個(gè)問題而誕生,他包含了這些公共的東西.然后所有需要使用該函數(shù)的.cpp,只需要
用#include包含進(jìn)去便可.以后需要修改,也只是修改一份內(nèi)容.
請注意不要濫用.h,.h里面不要寫代碼,.h不是.cpp的倉庫,什么都塞到里面.
如果在里面寫代碼,當(dāng)其他.cpp包含他的時(shí)候,就會(huì)出現(xiàn)重復(fù)定義的情況,
比如將函數(shù)func(){printf};放到頭文件a.h,里面還有一些a.cpp需要的聲明等;
然后你發(fā)現(xiàn)b.cpp需要用到a.cpp里面的一個(gè)函數(shù),就很高興的將a.h包含進(jìn)來.
注意,#include并不是什么申請指令,他就是將指定的文件的內(nèi)容,原封不動(dòng)的拷貝
進(jìn)來.
這時(shí)候?qū)嶋H上a.cpp和b.cpp都有一個(gè)func()函數(shù)的定義.
如果這個(gè)函數(shù)是內(nèi)部鏈接static的話,還好,浪費(fèi)了一倍空間;
如果是extern,外部鏈接(這個(gè)是默認(rèn)情況),那么根據(jù)在同一個(gè)程序內(nèi)不可出現(xiàn)
同名函數(shù)的要求,連接器會(huì)毫不留情給你一個(gè)連接錯(cuò)誤!
http://www.cnblogs.com/shelvenn/archive/2008/02/02/1062446.html
一. Perspective and Metaphor
Platform
Kernel
Framework
二. Philosophy and discipline
Be aware of context
Extreme maintenance
Be pragmatic
Extreme abstract: Program to an interface (abstraction), not an implementation
Extreme separation of concerns
Extreme readability
Testability
No side effect
Do not repeat yourself
三. Principle
DIP ,dependency inversion of control
OCP , open close
LSP , liskov substitute
ISP , interface segregation
SRP , single responsibility
LKP, Lease knowledge principle
四. design pattern
Construction
Behavior
Structure
五. anti-pattern、bad smell
Long method
Diverse change
Repeated code
Talk to stranger
Pre optimize
六. algorithms
nLongN
Divided and conqueror
七. architecture
Hierarchal
Pipes and filter
Micro kernel
Broker
Black Board
Interpreter
八. Distributed & concurrent
What to concurrent
Scalability
Stretch key dimensions to see what breaks
九. languages
Ruby
Erlang
assemble
C
C++
Java
Python
Scala
Be ware of different program paradigms.
十. Performance
Minimize remote calls and other I/O
Speed-up data conversion
release resource as soon as possible
十一. architectures' future
軟件設(shè)計(jì)思想的發(fā)展邏輯,大致是提高抽象程度 ,separation of concern 程度。
fn(design )= fn1(abstraction )+ fn2(separation of concern).
由于大規(guī)模數(shù)據(jù)處理時(shí)代的來臨,下一代設(shè)計(jì)范式的重點(diǎn):
1. 將是如何提高distributed(--concurrent) programing 的抽象程度 和 separation of concern 程度。
2. dsl ,按照以上的公式,也確實(shí)是一個(gè)好的方向。
十二. Reference
<art agile software development>
<prerefactor>
<design patterns>
<beautiful architecture>
<refactor>
<pattern oriented software architecture>
<extreme software development>
<beautiful code>
<patterns for parallel programming>
<java concurrent programming in practice>
<java performance tuning>
<the definite guide to hadoop>
<greenplum>
<DryadLINQ>
<software architecture in practice>
<97 things architecture should known>
http://en.wikipedia.org/wiki/Programming_paradigm
拷貝
mingliu.ttc simsun.ttf SURSONG.TTF tahomabd.ttf tahoma.ttf verdanab.ttf verdanai.ttf verdana.ttf verdanaz.ttf
#mv simsun.ttc /usr/share/fonts/local/simsun.ttf
#cd /usr/share/fonts/local/
sudo mkfontscale
sudo mkfontdir
sudo fc-cache
cp fonts.scale fonts.dir
sudo chmod 755 *
sudo chkfontpath --add /usr/share/fonts/local/
#/etc/init.d/xfs restart
查檢是否安裝成功
fc-list |grep Sim
NSimSun:style=Regular
SimSun:style=Regular
SimSun\-PUA:style=Regular
experience learned.
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
以前聽過用友的牛人關(guān)于軟件設(shè)計(jì)范型的時(shí)代劃分,記得不太準(zhǔn)確,不過基本上是業(yè)界公認(rèn)的。
大致上是:過程式、面向?qū)ο蟆⒔M件、面向服務(wù)。
未來呢?我忘記了,抑或是 dsl ?
我以往也沒有自己的認(rèn)識,不過,最近我有自己的看法
軟件設(shè)計(jì)思想的發(fā)展邏輯,大致是提高抽象程度 ,seperation of concern 程度。
fn(design )= fn1(abstraction )+ fn2(seperation of concern).
由于大規(guī)模數(shù)據(jù)處理時(shí)代的來臨,下一代設(shè)計(jì)范式的重點(diǎn):
- 將是如何提高concurrent programing 的抽象程度 和 seperation of concern 程度。
- 至于dsl ,我研究不多,不過,按照以上的公式,也確實(shí)是一個(gè)好的方向。
對于英文詞語的使用,是因?yàn)?,我想更能表達(dá)我的意思,不至于誤解。見諒。
歡迎批評指正!
最近看的東西,備忘。
Dryad
DryadLinq
GreenPlum。
技術(shù)上看:
Dryad 牛
商業(yè)上看,
只有microsoft(Dryad),oracle (?),ibm (?)
其他的cloud data engine 似乎難免被收購宿命,一如bea 。。。。etc .
?google (
Sawzall) ?amazon
?hadoop ,pig
中國:
?友友系統(tǒng)
Saas business
一. chain
customer : operator :application :feature: platform .
二. operator
三. application
office
erp
mall
game
四. feature
search engine
monitor system
security
dynamic language
special db system
special file system
五. platform
virtual computing resource system
cloud file system
cloud db system
cloud os
六. chance
big fish or small fish should find their way to survive.
安裝和配置簡述
* 英文指南
* 配置tomcat
o 修改 server.xml ,在connector 加 URIEncoding="UTF-8"
o 修改 catalina.sh ,加一行 CATALINA_OPTS="-DHUDSON_HOME=~/apprun/hudsonhome/ -Xms512m -Xmx512m"
+ 其中 HUDSON_HOME 是 hudson 的配置和運(yùn)行文件所在地
o 修改 tomcat-users.xml
+ <role rolename="admin"/>
+ <user username="hudson" password="hudson" roles="admin"/>
* 把下載的hudson.war 放在 tomcat 的webapps 下,hudson 會(huì)自動(dòng)啟動(dòng)起來,部署就完成了
o 可以訪問,比如 http://****:18080/hudson/
* 安裝 jdk
* 安裝 ant
* 配置hudson
o 配置和管理需要登陸 ,login
o 打開管理頁面,比如 http://****:18080/hudson/configure
o 配置安全 ,Enable security ,兩個(gè)選項(xiàng):Delegate to servlet container --〉Legacy mode
o 配置 jdk 路徑, 比如 /home/**/tools/jdk1.6.0_13/
o 配置 ant 路徑, 比如 /home/**/apprun/ant171
o 配置 System Admin E-mail Address ,//寫一個(gè)很多項(xiàng)目公用的email
o 記得 save
* 新建一個(gè)job
o 配置和管理需要登陸 ,login
o new job ,選項(xiàng) :Build a free-style software project
o 配置 ,比如 :**:18080/hudson/job/icontent/configure
+ 填寫svn 路徑 ,比如 :http://svn.****
+ Build Triggers,選Poll SCM ,schedule 符合 cron 規(guī)則
+ Build ,invoke ant ,填寫 ant target
+ Post-build Actions ,選 E-mail Notification , Recipients 填寫郵件地址
* 配置linux 的環(huán)境變量
o vi .bash_profile
o JAVA_HOME=$HOME/tools/jdk1.6.0_13
o PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:$HOME/apprun/ant171/bin
o LANG=zh_CN.GB2312 //encoding 與.java 源代碼文件的編碼一致 ,這樣javadoc 不會(huì)有警告
o LC_CTYPE=zh_CN.GB2312
easy!
great tool!
1. hibernate 變得不太重要了,jdbc 就很好
2. 數(shù)據(jù)庫不夠用了,bdb
3. bdb 不夠用了, 自己寫b+ tree
4. java 不行了,得用 c++
看來,這個(gè)轉(zhuǎn)變是個(gè)革命。搞不好得丟飯碗。
從想做一個(gè)創(chuàng)業(yè)者,到想做一個(gè)proferssional 。
<西津渡圖解軟件項(xiàng)目管理 〉從1年半之前,每當(dāng)有新的感受,就修訂一些。為自己的成長作個(gè)備注吧。
code-block with mingw ,setup .
set path=c:\program file\code blocks\mingw\bin;%path%
bjam --toolset=gcc-3.4.5 --prefix=d:\boost\b137345 --build-type=complete install
很久沒有來blogjava 了。
一個(gè)原因是,關(guān)注的內(nèi)容與blogjava 的東西,重疊的太少了。
不過,我也納悶,我該去哪里找自己的同好?
blogjava 在云計(jì)算,web2.0 ,這些前途領(lǐng)域,沒有什么內(nèi)容。
struts,hibernate,spring, acegi,lucene 這些都是成熟的東西了。
說一下我最近用過的東西:
hadoop,hbase,zookeeper,深入研究了java concurrent.
下一步的方向是寫一個(gè),distribute document oriented file system.
技術(shù)和互聯(lián)網(wǎng)的發(fā)展,絕對是web2.0,云計(jì)算,兩端厚的架構(gòu)。blogjava 也該多這方面的內(nèi)容了。
Conducting and Reviewing the Software Design Model
The design model resides at the core of the software engineering process. It is the place where quality is built into the software (and the place where quality is assessed. For this checklist, the more questions that elicit a negative response, the higher the risk that the analysis model will adequately serve its purpose. . For this checklist, the more questions that elicit a negative response, the higher the risk that the design model will not adequately serve its purpose.
General issues:
o Does the overall design implement all explicit requirements? Has a traceability table been developed?
設(shè)計(jì)對需求的匹配?
o Does the overall design achieve all implicit requirements?
o Is the design represented in a form that is easily understood by outsiders?
易理解?
o Is design notation standardized? Consistent?
o Does the overall design provide sufficient information for test case design?
可測試。
o Is the design created using recognizable architectural and procedural patterns?
常用的架構(gòu) 和模式?
o Does the design strive to incorporate reusable components?
重用組件?
o Is the design modular?
模塊化
o Has the design defined both procedural and data abstractions that can be reused?
重用的過程 / 數(shù)據(jù) 抽象?
o Has the design been defined and represented in a stepwise fashion?
逐漸細(xì)化的表述?
o Has the resultant software architecture been partitioned for ease of implementation? Maintenance?
可部署性? 可維護(hù)性?
o Have the concepts of information hiding and functional independence been followed throughout the design?
封裝性?
o Has a Design Specification been developed for the software?
文檔?
For data design:
o Have data objected defined in the analysis model been properly translated into required data structured?
數(shù)據(jù)映射with analysis?
o Do the data structures contain all attributes defined in the analysis model?
數(shù)據(jù)屬性?
o Have any new data structures and/or attributes been defined at design time?
新的數(shù)據(jù)結(jié)構(gòu)?
o How do any new data structures and/or attributes related to the analysis model and to overall user requirements?
用戶需求與數(shù)據(jù)結(jié)構(gòu)匹配嗎?
o Have the simplest data structures required to do the job been chosen?
數(shù)據(jù)結(jié)構(gòu)簡單嗎?
o Can the data structures be implemented directly in the programming language of choice?
編程語言適合數(shù)據(jù)結(jié)構(gòu)?
o How are data communicated between software components?
軟件組件之間的數(shù)據(jù)交換?
o Do explicit data components (e.g., a database) exist? If so, what is their role?
數(shù)據(jù)庫?
For architectural design:
o Has a library of architectural styles been considered prior to the definition of the resultant software architecture?
架構(gòu)模式?
o Has architectural tradeoff analysis been performed?
架構(gòu)分析的tradeoff?
o Is the resultant software architecture a recognizable architectural style?
認(rèn)可的架構(gòu)風(fēng)格?
o Has the architecture been exercised against existing usage scenarios?
架構(gòu)有應(yīng)用示例嗎?
o Has an appropriate mapping been used to translate the analysis model into the architectural model?
分析和架構(gòu)之間的mapping?
o Can quality characteristics associated with the resultant architecture (e.g., a factored call-and-return architecture) be readily identified from information provided in the design model?
架構(gòu)的質(zhì)量特點(diǎn)?
For user interface design:
o Have the results of task analysis been documented?
o Have goals for each user task been identified?
o Has an action sequence been defined for each user task?
o Have various states of the interface been documented?
o Have objects and actions that appear within the context of the interface been defined?
o Have the three "golden rules" (SEPA, 5/e, p. 402) been maintained throughout the GUI design?
o Has flexible interaction been defined as a design criterion throughout the interface?
o Have expert and novice modes of interaction been defined?
o Have technical internals been hidden from the causal user?
o Is the on-screen metaphor (if any) consistent with the overall applications?
o Are icons clear and understandable?
o Is interaction intuitive?
o Is system response time consistent across all tasks?
o Has an integrated help facility been implemented?
o Are all error message displayed by the interface easy to understand? Do they help the user resolve the problem quickly?
o Is color being used effectively?
o Has a prototype for the interface been developed?
o Have user's impressions of the prototype been collected in an organized manner?
For component-level design:
* Have proof of correctness techniques (SEPA, 5/e, Chapter 26) been applied to all algorithms?
算法正確性?
* Has each algorithm been "desk-tested" to uncover errors? Is each algorithm correct?
算法?
* Is the design of the algorithm consistent with the data structured that the component manipulates?
算法?
* Have algorithmic design alternatives been considered? If yes, why was this design chosen?
替代算法考慮了嗎?
* Has the complexity of each algorithm been computed?
每個(gè)算法的復(fù)雜性考慮了嗎?
* Have structured programming constructs been used throughout?
結(jié)構(gòu)好嗎?
西津渡最近在修改
99街購物搜索引擎,www.99jie.com
根據(jù)體會(huì),修訂了圖解軟件項(xiàng)目管理一文。這是今年以來的第三次較大修訂。
有需要者請下載。
西津渡圖解軟件項(xiàng)目管理
下邊是目錄。
第一章 項(xiàng)目管理的目標(biāo)
一、 產(chǎn)品,周期,成本的約束。
二、 關(guān)鍵路徑管理
三、 可行性分析很重要
四、 人際技巧
五、 談判技巧
第二章 項(xiàng)目過程
一、 計(jì)劃階段
二、 架構(gòu)階段和技術(shù)攻關(guān)
三、 迭代階段
四、 結(jié)束階段
第三章 分析,形成specification
一、 最重要的是specification 發(fā)揮作用
二、 重要的創(chuàng)造性工作
三、 選擇適合的表達(dá)方式
四、 數(shù)據(jù)以及數(shù)據(jù)的key 和約束
五、 測試腳本
六、 Review ,評審
第四章 設(shè)計(jì)系統(tǒng)UI
一、 一幅圖勝過千句話
第五章 設(shè)計(jì),code ,build ,test
第六章 部署和重構(gòu)
第七章 風(fēng)險(xiǎn)
一、 分析風(fēng)險(xiǎn)
二、 技術(shù)風(fēng)險(xiǎn)
三、 所有的風(fēng)險(xiǎn)是人的風(fēng)險(xiǎn),trust and capable
四、 記住50%以上的軟件項(xiàng)目以失敗告終
五、 所有的風(fēng)險(xiǎn)是管理的風(fēng)險(xiǎn),遵循一套項(xiàng)目管理哲學(xué)
第八章 保持項(xiàng)目的進(jìn)展
一、 對項(xiàng)目負(fù)責(zé),做出決定
二、 讓進(jìn)展可見,持續(xù)集成
三、執(zhí)行,并檢查
四、 解決沖突,大家都是兄弟姐妹
五、 能擔(dān)當(dāng)者是項(xiàng)目經(jīng)理
六、 關(guān)鍵路徑的變更
第九章 總結(jié)經(jīng)驗(yàn)
第十章 一些效率關(guān)鍵指標(biāo)
第十一章 項(xiàng)目管理工具
第十二章 參考
第十三章 口訣
http://www.xker.com/edu/dev/104/0652109570034579.html
十二、不要在循環(huán)中調(diào)用synchronized(同步)方法
方法的同步需要消耗相當(dāng)大的資料,在一個(gè)循環(huán)中調(diào)用它絕對不是一個(gè)好主意。
例子:
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{//在一個(gè)同步塊中執(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),會(huì)極大的影響性能,如果編譯JIT被關(guān)閉或者你所使用的是一個(gè)不帶JIT的JVM,性能會(huì)將下降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)體中實(shí)例化變量
在循環(huán)體中實(shí)例化臨時(shí)變量將會(huì)增加內(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)體外定義變量,并反復(fù)使用
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);
}
}
}
二十一、盡可能的使用棧變量
如果一個(gè)變量需要經(jīng)常訪問,那么你就需要考慮這個(gè)變量的作用域了。static? local?還是實(shí)例變量?訪問靜態(tài)變量和實(shí)例變量將會(huì)比訪問局部變量多耗費(fèi)2-3個(gè)時(shí)鐘周期。
例子:
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
http://www.javafan.net/menu/jczs/200701/20070108185247.html
1). 簡單的認(rèn)為 .append() 效率好于 "+" 是錯(cuò)誤的!
2). 不要使用 new 創(chuàng)建 String
3). 注意 .intern() 的使用
4). 在編譯期能夠確定字符串值的情況下,使用"+"效率最高
5). 避免使用 "+=" 來構(gòu)造字符串
6). 在聲明StringBuffer對象的時(shí)候,指定合適的capacity,不要使用默認(rèn)值(18)
7). 注意以下二者的區(qū)別不一樣
- String s = "a" + "b";
- String s = "a";
s += "b";
關(guān)鍵點(diǎn)
1. 無論何時(shí)只要可能的話使用字符串字面量來常見字符串而不是使用new關(guān)鍵字來創(chuàng)建字符串。
2. 無論何時(shí)當(dāng)你要使用new關(guān)鍵字來創(chuàng)建很多內(nèi)容重復(fù)的字符串的話,請使用String.intern()方法。
3. +操作符會(huì)為字符串連接提供最佳的性能――當(dāng)字符串是在編譯期決定的時(shí)候。
4. 如果字符串在運(yùn)行期決定,使用一個(gè)合適的初期容量值初始化的StringBuffer會(huì)為字符串連接提供最佳的性能。
q16 版.
安裝后,把所有的dll 拷貝到system32.
經(jīng)過一段時(shí)間的折騰。一堆東西能避免使用就避免使用。
castor, dwr, acegi, 幾乎扔掉。
spring ,hibernate 也只用在適當(dāng)?shù)膱龊稀?br />
struts2 ,也只用在適當(dāng)?shù)膱龊稀?br />
一些偷懶的技術(shù),盡量避免。
opensession in view.
一直困擾于 indexSearcher 的重新 new ,query filter 的cache 沒了。
重讀solr ,發(fā)現(xiàn)非常好。也許我應(yīng)該考慮用 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),我可以用不同的方式實(shí)現(xiàn)cache ,也許在我的情況下比solr 的方式更好。
在一臺 8G ,2 dual core cpu 的2u , struts2+spring+hibernate .
開源軟件,用什么樣的 proxy, cache, web container 達(dá)到最好的性能。
瓶頸在于:
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 個(gè) tomcat ,應(yīng)該可以達(dá)到較好的性能。
環(huán)境 apache + tomcat , ajp 連接。
apr
jvm 優(yōu)化
nio , connector 優(yōu)化。
c3p0.
情況下
用jmeter ,tomcat 到 1000 并發(fā)沒有問題。
發(fā)現(xiàn)一個(gè)問題: apache 的 250 個(gè) worker 限制。
導(dǎo)致單純的 tomcat 性能更好。比用ajp.
一個(gè) threadgroup, 3個(gè)http sample, 1000 ,5428。
看來,需要編譯 apache.
http://www.mchange.com/projects/c3p0/#configuration_properties
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 。 可能和測試過程有關(guān)。
maxStatement 加上, 3600。嚴(yán)重影響性能。
擴(kuò)大 xms xmx 512 ,957
tree 結(jié)構(gòu)很常見,當(dāng)persist 到數(shù)據(jù)庫中。
有些操作,在db 中更好。
1。取得所有的葉子節(jié)點(diǎn)。
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 時(shí),如果 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.》
一、one-many ,需要一個(gè)有序的list. 建議影射方式 :
private List _items;
<bag
name="items"
inverse="true" //盡量使用雙向關(guān)聯(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 適用
通過主鍵進(jìn)行關(guān)聯(lián)
相當(dāng)于把大表拆分為多個(gè)小表
例如把大字段單獨(dú)拆分出來,以提高數(shù)據(jù)庫操作的性能
三、composite element ,必須依賴的導(dǎo)航關(guān)系
<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 , 很復(fù)雜,有點(diǎn)不明白
<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>
五、繼承關(guān)系, 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è)務(wù)邏輯封裝在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;
# }
searcher 新開后,cache 會(huì)失效。
所以,重新開 searcher 的頻率對于很重的訪問量來說,不能太頻繁。這樣查詢肯定有不能同步的問題。
對于不要求同步的場景來說,夠了。
繼續(xù)研究。
在 conf/catalina/localhost/ 建 solr.xml
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 的結(jié)構(gòu)
conf
data/index
清凈拳。
拳打六根清凈,念佛
拳打陰陽分明,悟空
拳打呼吸到腫,得道。
拳打恍恍惚惚,歸無。
tomcat6 , jetty6 采用 jsp2.1。
由于 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 就不會(huì)有問題了。
辦法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)在的疑問
在一個(gè)頁面中采用兩個(gè) el 引擎,是否會(huì)對性能造成一定影響?
較小。
LoadModule cache_module modules/mod_cache.so
LoadModule 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>
LoadModule proxy_http_module modules/mod_proxy_http.so
<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 情況下性能應(yīng)該比 mod_http_proxy 好。
關(guān)閉 缺省主機(jī)的 log
#customLog logs/access.log common
在 virtualhost 中加
CustomLog logs/lele_access.log common
LoadModule mod_rewrite
在 <virtualHost> 中
RewriteLogLevel 3
RewriteLog "f:/temp/logs/sosorewrite.log"
RewriteEngine on
RewriteRule ^(.*)\.html$ /index.php
一、修改 http.conf
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, 性能會(huì)比較好。
一、 在 http.conf 末尾加
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 測試配置
只是愈多愈好。
配置 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"
** 對應(yīng)apache2.2 必須用這個(gè)**
2. AddType application/x-httpd-php .php
3. if module dir_modle ,
DirectoryIndex index.php ,index.html
配置php.ini ,啟動(dòng) mysql
extension=php_mysql.dll
extension=php_mysqli.dll
測試
phpinfo.php
<? echo phpinfo(); ?>
ok.
摘要: 最近覺得一個(gè)網(wǎng)站架構(gòu)師,應(yīng)該把高性能問題搞得很好。大致整理一下。今后會(huì)在幾個(gè)方面繼續(xù)深入。
本文的圖形,沒有上來。需要看完整的,請下載 :西津渡如何設(shè)計(jì)軟件
高性能是其中的部分內(nèi)容。目前還不夠深思熟慮,請有經(jīng)驗(yàn)者指正。多謝。
閱讀全文
修訂了一版圖解軟件項(xiàng)目管理。
圖解軟件項(xiàng)目管理加強(qiáng)的部分:
軟件項(xiàng)目的商業(yè)背景, 項(xiàng)目的平衡術(shù), 關(guān)鍵路徑的管理。
這個(gè)模式一直沒有好好的理解。最近作IM 相關(guān)的應(yīng)用,才明白了。
就是兩個(gè)人之間要溝通,不是直接,而是通過 mediator.
也就是 ,不是
user1.sendMessage(user2,"some message");
而是
user1.getMediator().sendMessage("user2","some message");
有什么好處呢:
職責(zé)分離:mediator 完成自己該承擔(dān)的職責(zé)。
mediator 也可以搞這搞那。
插一段實(shí)際代碼:
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;
}
}
摘要: 原則: "更多的考慮用對象組合機(jī)制,而不是用對象繼承機(jī)制". 更多的重用。
幾種模式的區(qū)別:
adapter 意圖是把已經(jīng)有的部件,adapt 過來,到一個(gè)需要不同接口的部件。
bridge 的意圖是讓 abstract. 以及 implementor 可以用在更多的地方。 (費(fèi)這么大勁,目的就是重用)
proxy 的意圖是在proxy 中搞點(diǎn)什么。
下面是在junit 中run 一段別人的代碼,演示bridge 模式。
閱讀全文
根據(jù)我以前的經(jīng)驗(yàn),以及最近的struts2 的開發(fā)。我感覺的struts2 的性能問題。
找了一篇 討論 struts2 performance 的文章:
http://www.nabble.com/Struts-2-performance-t4053401.html繼續(xù)閱讀 struts2 的 performance tunning :
http://struts.apache.org/2.x/docs/performance-tuning.html我的判斷:
對于heavy user 的website , 不用 struts2? (直接用servlet+jsp /or ??????)
對于few user 的 management 可以用 struts2.
學(xué)習(xí) stripes .
stripes download 正是我想要的。
theserverside 關(guān)于 stripes 的討論。
stripes great
摘要:
StAX the odds with Woodstox
剛讀了,感覺不錯(cuò)。
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
閱讀全文
我答scjp 比較差,所以感覺自己還不夠professional 。做了不少應(yīng)用,不過作為一個(gè)職業(yè)人士,基礎(chǔ)的東西也應(yīng)該很好。這兩天惡補(bǔ)一下。
swing 也要學(xué)習(xí)。
1. java performance tuning
2. java5 's new feature ok
3. jdbc performance
最近一直用已有的知識,再規(guī)劃一下,最近的學(xué)習(xí)重點(diǎn)
1.rick client 的全面掌握
以前用dwr ,再復(fù)習(xí)一下 . ok ,prototypes . 07-08-01
2.db procedure
以前基本不會(huì)。
3.ejb3
高可靠性transaction
4. StAX, woodstox
學(xué)習(xí)一下新的xml 處理技術(shù)。 ok. 07-08-01
5.REST
新東西,很重要 . ok. 07-08-1
6.english
看來架構(gòu)師的工作機(jī)會(huì)還是比較多。
99 街 www.99jie.com ,是一個(gè)購物digg 網(wǎng)站。
以后撿周末空余時(shí)間,逐漸把功能補(bǔ)全了。
我再次踏入求職者隊(duì)伍。
領(lǐng)域建模頂級高手。目前做過的項(xiàng)目超過6個(gè)。參見我的blog<如何設(shè)計(jì)軟件〉.
spring,hibernate,webwork 頂級高手。目前做過的大小項(xiàng)目超過6個(gè)。
lucene 頂級高手。做過的項(xiàng)目超過兩個(gè)。
垂直搜索頂級高手。兩個(gè)spider 項(xiàng)目,一個(gè)價(jià)格更新項(xiàng)目。
軟件項(xiàng)目管理頂級高手。參見我的blog<圖解軟件項(xiàng)目管理〉。
留住客戶,促使客戶產(chǎn)生購買行為。這就是網(wǎng)站要做的。
白給錢,評測報(bào)告,網(wǎng)友推薦,商家的商譽(yù)。先行賠付。不滿意包換。1折。
我的比較購物網(wǎng)站的理想
1.與 b2c 商店合作拿數(shù)據(jù),承諾在5年內(nèi)傭金只很小的比例,如果銷售額不能達(dá)到某個(gè)值,不拿傭金
2.大規(guī)模的鋪服務(wù)器,吸收最大量的b2c 商家,保證性能
3.對通過我們網(wǎng)站購物的消費(fèi)者,提供無風(fēng)險(xiǎn)保證,先行賠付
4.管理商家的信譽(yù),對不能達(dá)到信譽(yù)的商家提高傭金比例
5.為今后的b2c 市場擴(kuò)展留下廣闊的收錢空間
這個(gè)商業(yè)模式的要點(diǎn)在于
a. 承擔(dān)中國的b2c 商家的信譽(yù)管理責(zé)任,這是無價(jià)之寶
a.數(shù)據(jù)主要不靠 spider, 與 EShopping 軟件提供商合作,直接用webService 方式拿數(shù)據(jù)
b. 數(shù)據(jù)由b2c 商家積極提供,保證質(zhì)量
c. 訂單跟蹤直接用 webservice 方式拿,保證及時(shí)可靠質(zhì)量。
pair programming
這個(gè)小項(xiàng)目只有我們兩個(gè)人,通過3天的pair programming ,我把自己的編程習(xí)慣,風(fēng)格,設(shè)計(jì)理念全部共享給同事。
我們一起思考業(yè)務(wù),設(shè)計(jì),項(xiàng)目進(jìn)展非常好。進(jìn)度提高一倍以上。
多年來,我?guī)缀醪豢习炎约旱慕?jīng)驗(yàn)分享給別人,如今念佛悔改,幾乎沒有一點(diǎn)保留。
pair programming 的好處在交流,在于知識的共享。
今后做項(xiàng)目也多了一個(gè)非常得力的幫手。
我自己考慮,今后我?guī)У乃许?xiàng)目成員,都要經(jīng)常交叉進(jìn)行pair programming.充分的交流。
總監(jiān),在于權(quán)利欲,在于毅力強(qiáng)。
系統(tǒng)分析員,在于綜合能力,在于靈活,在于平衡。
架構(gòu)師,在于執(zhí)著,在于超然物外。
小的項(xiàng)目,就容不了這么多人,項(xiàng)目經(jīng)理就夠了。
摘要: 讀書,編碼,架構(gòu)師之路,每天都在進(jìn)步。
閱讀全文
這個(gè)膚淺的東西,該有新的東西替代了。
計(jì)劃 《ddd 》,《設(shè)計(jì)模式、算法和架構(gòu)》,《分布式計(jì)算和data sharding>.
半年內(nèi)作完。
附件:
請下載。
如何設(shè)計(jì)軟件-我的體會(huì).rar
最近把一年多的工作總結(jié)了,先有 ‘圖解軟件項(xiàng)目管理’,又有這一篇。
如何設(shè)計(jì)軟件
-我的體會(huì)
李建奇
2007-02-05
我信心不足,勉強(qiáng)為之!
幾乎沒有普遍適用的原則。設(shè)計(jì)似乎是一種偶然的事情。所以還稱為手藝。
我陳述的主要是自己的經(jīng)驗(yàn)。
第一章理想的設(shè)計(jì)
三個(gè)判斷準(zhǔn)則:
l
維護(hù)成本低。
l
可以被重用。
l
易于理解。
第二章代碼是最好的設(shè)計(jì)工具
我的做法是,寫可以運(yùn)行的代碼,然后生成可以講解的圖形。
好處當(dāng)然是明顯的,避免出現(xiàn)普遍的錯(cuò)誤,看起來不錯(cuò)的設(shè)計(jì)其實(shí)不能用。
第三章不管怎樣,先讓結(jié)果出來
Engine can work : can produce the output 。
我的經(jīng)驗(yàn):
我總是這么做。比如:
抓取數(shù)據(jù):Jobo + htmlParser ,只是把別人的軟件連接起來,結(jié)果就出來了。
第四章硬核,總有一些東西是可以穩(wěn)定的
一、
發(fā)現(xiàn)領(lǐng)域的硬核,是關(guān)鍵的設(shè)計(jì)問題。
Firm core: model is steady
我的經(jīng)驗(yàn):
Merchandise 的三個(gè)要素:name, seller, price. 缺了任何一項(xiàng)就不是一個(gè)merchandise 了。
二、
事物之間的關(guān)系不外乎1對1,1對多,多對一
為什么不說多對多?
因?yàn)槲抑灰?/span>
Public
class A {
B b;
Collection <C> l;
}
為什么說多對一?
第五章模塊的主要接口(約定)是穩(wěn)定的
先把主要接口用簡單的方式實(shí)現(xiàn)出來,然后讓整個(gè)系統(tǒng)轉(zhuǎn)起來。
我的經(jīng)驗(yàn):
解析模塊的主要接口:
Public Object parse(String content , String url){ ……}
第六章功能可擴(kuò)展
一、
Observer 設(shè)計(jì)模式:
我的經(jīng)驗(yàn):
有一點(diǎn)類似:LogicOrParser ;
我知道的:
我認(rèn)為 JMX 是使用 Observer 模式。
二、
Chain of Responsibility :
我的經(jīng)驗(yàn):
n
StringReplacer : next ().
我知道的:
n
Lucene 的 filterChain
n
Web app 的 ServletFilter.
n
Lucene 的 TokenStream .
三、
Strategy 設(shè)計(jì)模式
可以增加新的策略。
我的經(jīng)驗(yàn)。
失敗的經(jīng)驗(yàn):
PricePattern
有一個(gè)地方用
InstanceOf 。
原因是:我不知道Spring 配置Collection 有無可以使用Interface 的!
誰知道?
成功的經(jīng)驗(yàn):
UrlPattern:一個(gè)基于hibernate 的 inheritance 映射的適用經(jīng)驗(yàn):
Public
interface UrlPattern {
Public Boolean isInstance( String
url ) ;
}
第七章模塊可插拔
一、
Programming to interface :最重要的設(shè)計(jì)原則
幾乎是所有好的設(shè)計(jì)的基石!
我的經(jīng)驗(yàn):
l
Spring 是我必用的工具。
l
UrlPattern:一個(gè)基于hibernate 的 inheritance 映射的適用經(jīng)驗(yàn):
Public
interface UrlPattern {
Public Boolean isInstance( String
url ) ;
}
l
HttpReader
當(dāng)我發(fā)現(xiàn) JoboHttpReader 不能滿足的時(shí)候,我用HttpClientHttpReader 替換了。
二、
組合優(yōu)于繼承
繼承破壞了可替換性。
我的經(jīng)驗(yàn):
我好幾次把 template method 模式轉(zhuǎn)移到Strategy 或者 command模式。
把 PriceUpdatorManager 遷移到 command 模式。
我現(xiàn)在基本不使用抽象類。
不過也有例外: AbstractHibernateDAO 一直在用。
三、
封裝, proxy pattern : managing third party APIs
我的經(jīng)驗(yàn):
把lucene 的使用封裝起來。
有兩個(gè)好處:
可替換。
封裝好的東西可以方便地用在別的地方。
四、
不要牽涉無關(guān)的東西 ISP ,interface segregation
principle ,或者叫 split interface
我的經(jīng)驗(yàn):
我有過幾次失敗的教訓(xùn),當(dāng)時(shí)的擔(dān)心,類太多了,類太小了。
后來有些改了,有些沒有。
抄錄一段話:<prefactoring >
Split a single
interface into multiple interfaces if multiple clients use different portions
of the interface .
第八章分離關(guān)注separation
of concerns
我的經(jīng)驗(yàn):
Spring 的 transaction 機(jī)制
我用SpringAop 和 ehcache 實(shí)現(xiàn) method cache ;
Acegi ,把安全管理分離出來。
第九章性能可擴(kuò)展
一、
線程池:
基本的提高性能的辦法。
我的經(jīng)驗(yàn):
blocked Queue :
Semaphore:
二、
分布式運(yùn)算:
我的經(jīng)驗(yàn):
基于RMI 的分布式使用。
第十章結(jié)構(gòu)
一、
減少依賴
我的經(jīng)驗(yàn):
似乎沒有?!
我知道的:
???在哪里?可能大家都是這么干的!
二、
分層:layering
我的經(jīng)驗(yàn):
總是使用的、不變的設(shè)計(jì): model, dao, service :
我對Lucene 的封裝:一個(gè)抽象。
Public
void addDocument( Document doc );
Public Document getDocumentById( Long id
);
第十一章設(shè)計(jì)思想的變遷
變遷太快,去年的最好的書,一年以后就過時(shí)了。
一、
主要的階段,以及framework 階段
Structure , 30年
OO , 10年
Pattern ,10 年
framework ,…… 這是我自己定義的。
主要的原因是,很多成熟的framework 的出現(xiàn),使得我們主要是學(xué)習(xí)好他們,然后把自己的領(lǐng)域吃透,用好這些
framework 就可以生產(chǎn)出較好的軟件。
二、
Jolt 圖書大獎(jiǎng)
2003
<agile software
development>
2004
<Waltzing with Bears:
Managing Risk on Software Projects>
2005
<headfirst design
pattern>
2006
<prefactoring >
2007
????
第十二章導(dǎo)師
l
我自己的項(xiàng)目經(jīng)驗(yàn)
l
Eric Gamma < design pattern>
l
Rod Johnson <SpringFramework>
l
Eric freeman <headfirst design pattern>
l
Gavin King <hibernate >
l
Pugh <prefactoring>
l
Robert <agile software development>
摘要: 軟件項(xiàng)目管理琢磨了十年,每次總結(jié),總要進(jìn)步一些,再次總結(jié)。2月5日修訂了一些內(nèi)容。
閱讀全文
also a dynamic site.session's cache also work for some nearly static page.
since it's need login user's info in page.application's scope isn't fit.
I also use ehcache for hibernate cache.
great solution!
<script language=javaScript> alert("me"); </script>?
I don't think follow should be in a java blog.
?I think the management thought I have some change.
?first I think management can't chease.Just choose those can met your culture.Ond shouldn't think use employee and kick off after.
?second ,I think corporation's existence not for profit or some great idea .It's for some people who have similar pursue and ideal to make life. these is most important.
?three, If you can't layer it ,you can't manage it.real layer should take clear boardary.
一、兩個(gè)陣營:
???? action request based : struts2.0 (mainly webwork2.2's technology)
???? component based. tapestry4 ,shale1 .
二、趨勢:
??? component based 會(huì)稍占優(yōu)勢,不過 action request based 也會(huì)占一定地位。
??? 這一點(diǎn),從05年 javaOne 給與 shale 的肯定。06年duke's choice 給與 tagpestry 的肯定可以看出來。
???
三、如何選擇:
??? shale1.0 將會(huì)于06年 8-12月之間,發(fā)正式版,
??? struts2.0 也將會(huì)在 06 年8-12 月,發(fā)正式版。
??? tapestry4 已經(jīng)是穩(wěn)定的版本。
??? 當(dāng)前啟動(dòng)的項(xiàng)目(06年8月):
?????? 對于一個(gè)有 action based 基礎(chǔ)的團(tuán)隊(duì),選 struts2 是可取的。
? ? ?? 對于一個(gè)全新的團(tuán)隊(duì),選 tapestry 似乎更加符合長期的發(fā)展。
?? ? ? shale 還需要一段時(shí)間的成熟期。比如1.1 以后,采用會(huì)更加穩(wěn)妥。
四、shale 與 tapestry
????? shale base on JSF 似乎有一些天時(shí)之利。不過tapestry 也可以采取很多的變化。
五、webFrameWork 的今后的發(fā)展feature的展望
???? webFrameWork 經(jīng)過多年的發(fā)展,基本的feature已經(jīng)達(dá)到很高的成熟度。
? ?? 包括:controller,view template,type converter,validation,ajax, 大的方面已經(jīng)有很多共識。
???? 重要的方向在于 DSL, 動(dòng)態(tài)語言,meta Programing 方面有一些有益的突破。
? ? ? ?
?
xfire+spring 發(fā)布service 是容易的。
activeMQ +spring jmsTemplae 也容易。jencks 作為consumer 也容易。
不過 soap over jms ,我沒有找到容易的方案。據(jù)說 xfire 解決了,可是文檔???
mule 下一步解決。等。
server 端,用ThreadExecutor 了。
這兩個(gè)原則最近有了切膚之痛的感受。
看來堅(jiān)持面向interface 的開發(fā)是必須的了。
問題在
? Abstract class 不能復(fù)雜,我想這也是template pattern 時(shí)候要注意的。
? template 要穩(wěn)定,不確定的東西不能放在template 中,當(dāng)然簡單的東西容易穩(wěn)定。
?
?否則必然違背 ocp 原則。
由于httpconnection 并不能總是很好的處理 “System.connectionTimeOut" 問題。
htmlParser 會(huì)裝死。
我想只能加一個(gè)monitor thread ,不過沒有完成。
??? html parser 在處理 一些網(wǎng)頁的時(shí)候,會(huì)出現(xiàn)亂碼'3f3f' .
??? 問題在于 頁面的charset=gb2312 ,而 頁面中有g(shù)bk 的碼 ,比如 'fb9c'.
??? 代碼可以驗(yàn)證,
? ? ??? 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"));
??? 不過,我并沒有解決這個(gè)問題。
由于“agile web with rails" 獲得了jolt 大獎(jiǎng),我實(shí)在無法不關(guān)心ruby 了。
基于最近的經(jīng)驗(yàn),我的看法:
?? 我不會(huì)采用rails 直到ruby 更加成熟,成熟的一些考慮因素。
?? 1. 需要更多的開源工具包
?? 2. killer 級別的IDE
?
? 第一個(gè)方面:工具支持。
?? 目前還不夠豐富,我關(guān)心的是
?? 1.cache
????? 僅有 memcache (perl 寫的)
?? 2.security 框架
?? 3.xml 處理
?? 4.database connection pool
?? 5. sitemesh 類似的工具
?? 6. urlrewrite
?? 7. rss
?? 8. log
?? 9. webservice
?
?? (也許ruby rails已經(jīng)有,只是我不知道)
?? 在java 環(huán)境中,web 項(xiàng)目
??? 我用 spring,hibernate,webwork,dwr ,ehcache ,castor,xfire,acegi ,dbcp(c3p0),log4j,ant,displayTag ,clickstream ,infoma ,etc.
?? spider 項(xiàng)目
???? jobo,htmlparser
?? 其他
????? tm4j 。
???
?? 我目前覺得java 環(huán)境,因?yàn)橛辛撕芏嗟墓ぞ呤歉咝实?,?dāng)然學(xué)習(xí)的過程也是漫長而艱苦的。
?? 由于所面對的項(xiàng)目不僅僅是 web 開發(fā),能找到解決的問題的java 工具,是非常幸福的,發(fā)明輪子是痛苦的。
??
?? 在 spring+hibernate+webwork+displayTag上,正在考慮用模版工具(freemaker/velocity..etc),生成crud 的代碼。(目前主要是拷貝)。如果能夠完成,web 開發(fā)的效率也是非常高的。
??
????
今天,研究scalablity 的問題。
看到國外建議用 perlbal ,不用 apache 的mod_proxy.
今后有時(shí)間再搭建環(huán)境,可惜 perl 不會(huì),有時(shí)間還需要學(xué)習(xí)一下。
ehcache 有非常棒的設(shè)計(jì),我自己感覺就不用oscache 了。
mysql 也支持partion 了。
??? error 級別,錯(cuò)誤,程序不能正常運(yùn)行
??? warn, 程序固然可以正常運(yùn)行,可是不是希望的邏輯
??? info ,至少應(yīng)該顯示程序的執(zhí)行邏輯
??? debug, 顯示數(shù)據(jù)
?? 所以info 對于發(fā)現(xiàn)運(yùn)行時(shí)的錯(cuò)誤很重要,要有效的撰寫。
統(tǒng)計(jì)結(jié)果,可以再用JasperReporter 整理一下,更好的滿足業(yè)務(wù)需要。
??? 這樣的設(shè)計(jì),避免了業(yè)務(wù)與日志的耦合。
??? 用PaginatedList ,得到干凈的URL,?page=1 .再用urlRewrite 一下。很好。
?目前沒有解決,用<c:url > 替換DisplayTag 中的一段代碼。
acegi 用到系統(tǒng)中,解決了權(quán)限的問題。
沒有上SSO,acegi 與CAS 的集成,要配置一下。
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
? <property name="attributes">
??? <map>
????? <entry key="myScAttr"><ref bean="mySpringBeanToExport"/>
??? </map>
? </property>
</bean>
用xml 文件作系統(tǒng)初始化。用CASTOR ,很好。xmlBean 太復(fù)雜。今后,JAXB2
解析HTML 大量采用表達(dá)式,用regExBuddy 調(diào)試,很棒。
用ACTIVEMQ 搭建了JMS 試驗(yàn)環(huán)境,很快用JMS API 試驗(yàn)成功。
如果真的做業(yè)務(wù),目前的mdp 可能還不夠成熟。
我用agsmail 搭了一個(gè)mail server.
用spring 的 MailTemplate ,很快就試驗(yàn)了javamail 。
選用了htmlParser .
htmlParser 結(jié)構(gòu)整潔。RegExpFilter 功能足夠強(qiáng)大。
用Builder 設(shè)計(jì)模式,解析出商品對象。
今后,看看用decorator 模式修飾一下.
選用了jobo.
heritrix ,代碼不是很整潔。
j-spider ,也不合用。
WebRobot.createFromXML("dir");就可以使用jobo.xml 來配置了。
regfilter 只能配置 allow="false";看源碼沒有問題,今后有時(shí)間要解決。
遇到奇怪的問題,是oracle 10g1.0.1 的問題,下載ojdbc14_g.jar 好了。
formitem ,getString("GBK");
<page:applyDecorator page="controller/servlet" decorator=""/>;
我開始選擇webwork.不過我現(xiàn)在喜歡springmvc,非侵入式設(shè)計(jì)是我喜歡的方式。
類型轉(zhuǎn)換,controller 的設(shè)計(jì)。validator.form 標(biāo)簽。是mvc 選擇的主要標(biāo)準(zhǔn)。
如果hibernate 制約了oo 設(shè)計(jì),就要考慮這種制約的代價(jià)。對于很重要的class ,如果不能用orm,就要放棄。
異步架構(gòu)
不要把所有的功能做成同步的。只要可以異步松耦合就應(yīng)該采用。
顯示邏輯非自動(dòng)化
只運(yùn)行一份(或者很少的幾個(gè)拷貝)的項(xiàng)目,架構(gòu)的時(shí)候,要盡量使得開發(fā)簡單。
不要考慮全部自動(dòng)化。
導(dǎo)航關(guān)系嚴(yán)重影響class 設(shè)計(jì)
好像記得booch 說過,一個(gè)系統(tǒng)的use case 不應(yīng)該超過20個(gè)。現(xiàn)在,我非常同意。太復(fù)雜的use case ,往往意味著對系統(tǒng)的抽象不夠。
自己感覺db table 的規(guī)模,也適用同樣的邏輯。