又到了該思考總結的時候

來源:互聯網
上載者:User

不知不覺,心又飄了起來。整個人也很輕。什麼也做不下去,什麼也不想做。總想著應該得到更多的回報,卻一直沒有付出更多的努力。

看演算法,看資料結構。看groovy,看nodejs,看jvm。什麼都看,卻懶於動手實踐。進展緩慢。

最近,在關注nodejs的應用。也在github上fork了幾個項目,希望能夠學到想學的東西。

今天,看了電影《最長的一日》。

寫了生產者消費者的程式。雖然想象中很簡單,但是,實現起來,還是把一些細節搞錯了。還好,最終搞定了,也搞明白了問題之所在。也算是今天的一點小收穫吧。

package test.multithread;public class MultiThreads {static int cnt = 0;static class Counter {private int cnt = 0;synchronized void inc() {cnt ++;}synchronized int get() {return cnt;}}public static void main(String[] args) {final Counter counter = new Counter();Thread producer = new Thread(new Runnable(){@Overridepublic void run() {while(true) {synchronized(counter) {counter.inc();int value = counter.get();System.out.println("producer : " + value);counter.notifyAll();try {counter.wait();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}if (value >= 1000) {break;}}}System.out.println("producer exited");}});Thread consumer = new Thread(new Runnable(){@Overridepublic void run() {while(true) {synchronized(counter) {int value = counter.get();System.out.println("consumer : " + value);counter.notifyAll();if (value >= 1000) {break;}try {counter.wait();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}System.out.println("consumer exited.");}});producer.start();consumer.start();}}

希望明天能把它用lock改寫一下。用clojure的STM改寫一下。

今天看到一個似曾相識的演算法題,就是不知怎麼搞了。翻到舊文章一看,一模一樣。太尷尬了。竟然一點印象都沒有了。

少說話,尤其是牢騷很多的時候,心情不好的時候。

心平氣和。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.