l main() method本身就是一個thread。
l 程式進入main()之後,就有兩個thread了,main()與garbage collection。
l 一個thread是一個object,要產生一個thread必須透過java.lang.Thread這個class。
l run() method的語法為”public void run() { ... }”。
l wait(); notify();及notifyAll();須在synchronized context下使用,不然會產生runtime exception:IllegalMonitorStateException。
l sleep()會丟出InterruptedException,使用需有try…catch,不然就要declare throws InterruptedException。
l 重覆呼叫同一執行緒的start(),會導致IllegalThreadStateException,為runtime exception
l synchronized不可用在constroctor。 |