Java多線程開發簡化類庫 SlicedBread

jopen 13年前發布 | 30K 次閱讀 Java

SlicedBread 是一個用于簡化 Java 多線程程序編寫的類庫。

SlicedBread is a library that makes it simpler to program multithreaded applications in Java. It does so by doing away with "classic" multithreaded staples - that is, shared state using thread-safe objects, locks and synchronizers - versus a set of single-thread processes that send and receive immutable messages. In a sense it is inspired by Erlang's messaging system. In another, the over 400 rich pages of "Java concurrency in practice" show how hard it is to write and debug a good-mannered multithreaded application in Java.

SlicedBread has been used in production systems for quite a bit of time now with no major issues, so I thought it was something that could benefit the community at large and I'm sharing it.

SlicedBread is licensed under the LGPL.

Sample application

The sample application is available at under the sources as:


    ch.loway.oss.sbDemos.helloWorld.HelloWorld

It basically spawns a couple of threads and sends each a simple message so that one prints "Hello" and the other "World".

The output looks something like:


    Hello world starting
    (Thread A#2) I am thread Thread A (created by Main)
    (Thread A#2) PRINTING: Hello
    (Thread A#2) Now Stopping
    (Thread B#3) I am thread Thread B (created by Main)
    (Thread B#3) PRINTING: World
    (Thread B#3) Now Stopping
    Message found: F:Thread A#2 T:Main#1 - ProcessStarted
    Message found: F:Thread A#2 T:Main#1 - ProcessEnded 
    Message found: F:Thread B#3 T:Main#1 - ProcessStarted
    Message found: F:Thread B#3 T:Main#1 - ProcessEnded 
項目地址: https://github.com/l3nz/SlicedBread

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!