4/28/2011

加速 PHP網頁執行

eAccelerator是一套不錯開源PHP網頁加速器,基本原理將PHP程式事先編譯過快取起來,且同時將PHP程式進行優化,號稱可以提升~30%(速度是真的提升)。

官方說明

eAccelerator is a free open-source PHP accelerator & optimizer. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.

4/13/2011

手動匯入Maven Local Repository

Sun 這個jai_imageio jar 似乎年代失修,一直找不到相對映的maven respo ,只能自行匯入本地儲存槽。

[code lang="shell"] mvn install:install-file -Dfile=jai-imageio-1.1.jar -DgroupId=javax.media -DartifactId=jai_imageio -Dversion=1.1 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true [/code]

maven pom.xml設定加入

[code lang="xml"] javax.media jai_imageio 1.1 [/code]

3/03/2011

JDBC關與不關問題

Jdbc programming 幾乎是寫Java程式存取資料庫一定會用到東西, 當利用Jdbc執行Sql時會有下面的寫法。

[code lang="java"] try{ #run sql ... }finally{ if(rs!=null) rs.close(); if(stmt!=null) stmt.close(); if(conn!=null) conn.close(); } [/code]

自行拿connection時需不需做囉唆事情 ?

2/11/2011

轉換 mp3 tag 編碼

統一轉成Unicode

[code lang="bash"] java -jar ~/id3iconv-0.2.1.jar -e Big5 *.mp3 [/code]

1/28/2011

Java Daemon 撰寫與佈署

這篇不是真正教如何設計Java Daemon,考量如何利用別人寫好的Java Daemon能夠比較容易整合於不同環境中。 如通常不會自行開發工作排程系統,利用已成熟Quarts為基礎往上堆應用程式,雖然是已成熟Java Daemon要如何整合於不同的作業系統(Linux, Windows, Mac) ?

這個問題說難不難說簡單不簡單,解決方案也五花八門。傳統方式就是撰寫 public static void main(String[]) 統一由這一支Java程式啟動服務,然後撰寫一堆shell呼叫, 雖然問題也是可以解決但是往後系統維護管理不易也沒有統一。

Apache Commons Daemon 專案滿不錯解決方案之一

...Most multi-user operating systems already have a way in which server applications are started and stopped. Under Unix based operating systems non interactive server applications are called daemons and are controlled by the operating system with a set of specified signals. Under Windows such programs are called services and are controlled by appropriate calls to specific functions defined in the application binary, but although the ways of dealing with the problem are different, in both cases the operating system can notify a server application of its imminent shutdown, and the application has the ability to perform certain tasks before its process of execution is destroyed.

1/17/2011

How to test job in Quartz

之前工作排程都是使用Java Quartz來設計,但確沒有好好想過要如何測試 (有時候承認不夠好或許就是進步泉源),真的很不應該!

工作排程環境要模擬也確實滿複雜,但可利用Mock觀念 讓我們追縱瞭解物件內部流程,確保物件活動如預期中運作。

Java Runtime exec

使用Java執行外部指令( ls, pwd....) OSX環境執行的很好,但在windows環境確整個掛住跑不動(Java真的有跨平台嗎?),搞了一下午才弄清楚。

原本程式極為單純容易,但是會在windows 環境掛住!

最後才發現原來祕密寫在Process Java Doc說明裡: