搜尋此網誌

2011年6月27日 星期一

Java Thread筆記

以下內容節錄自http://download.oracle.com/javase/tutorial/essential/concurrency/
  1. The Runnable object is passed to the Thread constructor for execution.
  2. Thread.sleep causes the current thread to suspend execution for a specified period.
  3. Interference happens when two operations, running in different threads, but acting on the same data, interleave. This means that the two operations consist of multiple steps, and the sequences of steps overlap.
  4. Synchronizing constructors doesn't make sense, because only the thread that creates an object should have access to it while it is being constructed.
  5. Another way to create synchronized code is with synchronized statements. Unlike synchronized methods, synchronized statements must specify the object that provides the intrinsic lock:
  6. Allowing a thread to acquire the same lock more than once enables reentrant synchronization. This describes a situation where synchronized code, directly or indirectly, invokes a method that also contains synchronized code, and both sets of code use the same lock. Without reentrant synchronization, synchronized code would have to take many additional precautions to avoid having a thread cause itself to block.
  7. Deadlock describes a situation where two or more threads are blocked forever, waiting for each other
  8. Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress.
  9. As with deadlock, livelocked threads are unable to make further progress. However, the threads are not blocked — they are simply too busy responding to each other to resume work.
  10. guarded block. Such a block begins by polling a condition that must be true before the block can proceed.

2011年6月26日 星期日

Java Polymorphism(多型)

Java多型可以藉由實作(Implementation)介面(Interface)來實現,或者是說藉由繼承 (Extends)來實現, 以下先介紹實作(Implementation)介面(Interface)的方式



===========================================
接下來是採取繼承(Extends)的方式


在這裡比較特別的是Human hm=new Man();這行敘述,雖然是以Human的型態宣告,
但是卻以Man class來實體化類別,所以在執行的時候還是以實體化的class為主.
為了更明確的觀察這個現象,我們把eat method改成下列:

private void eat(Man m){
m.eat();
}

在這個形況下會出現compile time error.
因為eat method只接受Man型態的物件,所以宣告為Human型態的物件無法被接受.
因為Human為Man的父類別(Super class)所以可以向下轉型(Cast)為Man型態:
(註,但woman類別無法轉型為man)

tester.eat((Man)hm);

可是如果我們接著把Human hm=new Man();的宣告改為Human hm=new Human();並不會出現compile time error,可是在執行的時候
因為實體化的類別為Human,並非Man,因此會出現runtime classcast exception.

在此我們得到一個結論:
Java在compile time的時候是檢查宣告的類別是否可以在某個方法裡被使用,
但是在執行的時候,會以實際的實體化類別所定義的方法來執行
======================================================
接下來我們討論當Man這個Class繼承了Human同時實作了介面Action,會更明顯的看出多型的威力



eat這個行為,可以從Human的觀點去執行,也可以從吃的這個動作的觀點來執行.



2011年6月23日 星期四

勝X和X達真是扶不起來!!

雖然可以參股大陸投資8.5代廠,可是今天股價還是下跌.
跟大陸人做生意,台灣永遠不會贏的.
況且這兩檔融資都太高了,線型全部是大空頭排列
還有人敢砸錢去買,
等融資清空了,才值得考慮要不要進場

2011年6月20日 星期一

真替台灣的學子擔心

天啊..一代不如一代,難怪台灣競爭力越來愈差,
分數低能進大學是制度的關係,竟然用這麼蠢的解決方法
這跟bug不解,直接mark掉意思差不多,問題還是在阿....
哀..想起以前一年一次聯考,大學率取率50%的時代,現在學生太爽了啦
考試還可以吹冷氣哩.以前被笑說大學生的程度比不上以前高中,
那現在的大學生程度只剩國中了嗎?
所以現在大學生也別怨起薪低,東抱怨西抱怨了.
這麼爛的程度要請你就偷笑了.
http://tw.news.yahoo.com/article/url/d/a/110620/4/2tlze.html

加權指數逆價差過大-->看箱型盤整

168點左右的逆價差,扣掉除權息144點,還有20點左右價差,
在逆價差的時候放空期貨,沒有很多肉,
反而應該是買期貨賣台灣50或與大盤連動大的權值股來套利.
大體而言就是要賣現貨股票,所以大盤要漲的機率很低,
要大跌似乎也不容易,畢竟今年有難得的選舉行情在支撐著指數,
我們這種小股民只好放空高融資的個股來做為投資的方向

2011年6月18日 星期六

人類的慾望大於實際的需求

人類的慾望大於實際的需求,所以要不斷過度的消費地球的資源,來滿足慾望,才會造成通膨,才會造成溫室效應,可惜人類的慾望只會擴大不會減少. 這其中又以商人是頭號戰犯,所有的泡沫化都是商人造成的.因為商人從來不會嫌錢賺太多.而會一直創造這個產品有多好有多棒,沒有了他,你就落伍了,就趕不上潮流.有1代就一定有2,3,4,5代,就一定有升級加強版.可是回過頭來想一想,在你身邊的每一樣產品,真的是必須要有的嗎?