Jetlang 提供了一個高性能的Java線程庫,該庫是 JDK 1.5 中的 java.util.concurrent 包的補充,可用於基於併發消息機制的應用。該類庫不提供遠程的消息功能,其設計的宗旨是實現一個內存中的消息傳遞機制:java
主要特色有:併發
All messages to a particular Fiber are delivered sequentially. Components can easily keep state without synchronizing data access or worrying about thread races.app
Single Fiber interface that can be backed by a dedicated thread or a thread pool.性能
Supports single or multiple subscribers for messages.spa
Subscriptions for single events or event batching線程
Single or recurring event schedulingscala
High performance design optimized for low latency and high scalability設計
Publishing is thread safe, allowing easy integration with other threading models.code
Low Lock Contention – Minimizing lock contention is critical for performance. Other concurrency solutions are limited by a single lock typically on a central thread pool or message queue. Jetlang is optimized for low lock contention. Without a central bottleneck, performance easily scales to the needs of the application.orm
Fiber fiber =
new
ThreadFiber();
fiber.start();
final CountDownLatch latch =
new
CountDownLatch(2);
Runnable toRun =
new
Runnable(){
public
void
run(){
latch.countDown();
}
};
//enqueue runnable for execution
fiber.execute(toRun);
//repeat to trigger latch a 2nd time
fiber.execute(toRun);
latch.await(10, TimeUnit.SECONDS);
//shutdown thread
fiber.dispose();