顯示具有 Java 標籤的文章。 顯示所有文章
顯示具有 Java 標籤的文章。 顯示所有文章

2015/05/22

Apache Usergrid 在 CentOS 7 安裝步驟

是按照筆記打的,可能和實際的狀況不一樣,少打了一些切換資料夾的指令

備註
如果用Java 8來做的話會有以下的錯誤,這時候就要確認一下所用的java版本
Failed to convert property value of type 'me.prettyprint.cassandra.service.clock.MicrosecondsClockResolution' to required type 'java.lang.String' for property 'clockResolution'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [me.prettyprint.cassandra.service.clock.MicrosecondsClockResolution] to required type [java.lang.String] for property 'clockResolution': no matching editors or conversion strategy found 

參考資料:
http://usergrid.readthedocs.org/en/latest/deploy-local.html http://usergrid.incubator.apache.org/docs/deploy-local/
http://foorious.com/devops/usergrid/install-trusty/
http://foorious.com/devops/cassandra-cluster-trusty-install/
http://www.liquidweb.com/kb/how-to-install-cassandra-on-centos-7/
http://tecadmin.net/install-tomcat-8-on-centos-rhel-and-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-a-centos-7-server

2013/02/04

關於Java裡Integer類別的==

我們都知道,在Java中的==比較的是"物件"的參照是否相等,並不會自動使用物件本身的值做比較。

但當Integer這個類別被使用到時,其-127~128的值會先被Integer類別給cache住,也因此若在Integer類別上使用==時,不同的參照方式在不同範圍內的值會有不同的結果。

直接assign,或是使用Integer.valueOf(int)的時候,在-127~128內的值會參照到同樣的物件,也就是==會比較到相同的物件。

使用new Integer(int)的方式時,因為各別產生新的物件,因此比較的會是不同物件。

其他wrapper classes(Byte, Short, Long, Character)也有相同的cache機制,cache的範圍各不相同,Float則沒有此機制。
另外BigDecimal也有此機制,範圍為0~10。

參考來源:
  Immutable Objects / Wrapper Class Caching

2012/10/09

2012/08/28

不論是否有錯誤的地址都要寄出信給正確地址收件者

目的:在JavaMail中,會遇到要寄給很多個Recipients的狀況,但是在預設的情況下,Mail Server 若發現提交的多個InternetAddress或Address中有一個有錯,例如"User unknown"或是"Invalid Address",則會直接停止動作不寄信,就算其他的地址是正確的也不會寄。

解法:將mail.smtp.sendpartial屬性設為true

Properties props = new Properties();
props.put("mail.smtp.sendpartial", "true");


注意:
  • 是"true"不是true,要傳進去的是字串才對。
  • 就算設成true也不一定會被 Mail Server接受,最終還是看Mail Server。
  • 建議還是在使用前,先將地址做些Regexp驗證,順便把valid跟invalid的Address做分類。可搜尋email address pattern,有各式各樣的Pattern可用。

參考: