java jetlang_Jetlang

软件简介

Jetlang 提供了一个高性能的Java线程库,该库是 JDK 1.5 中的 java.util.concurrent

包的补充,可用于基于并发消息机制的应用。该类库不提供远程的消息功能,其设计的宗旨是实现一个内存中的消息传递机制:

主要特点有:

All messages to a particular Fiber are delivered sequentially. Components can easily keep state without synchronizing data access or worrying about thread races.

Single Fiber interface that can be backed by a dedicated thread or a thread pool.

Supports single or multiple subscribers for messages.

Subscriptions for single events or event batching

Single or recurring event scheduling

High performance design optimized for low latency and high scalability

Publishing is thread safe, allowing easy integration with other threading models.

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.

示例代码:

// start thread backed receiver.

// Lighweight fibers can also be created using a thread pool

Fiber receiver = new ThreadFiber();

receiver.start();

// create java.util.concurrent.CountDownLatch to notify when message arrives

final CountDownLatch latch = new CountDownLatch(1);

// create channel to message between threads

Channel channel = new MemoryChannel();

Callback onMsg = new Callback() {

public void onMessage(String message) {

//open latch

latch.countDown();

}

};

//add subscription for message on receiver thread

channel.subscribe(receiver, onMsg);

//publish message to receive thread. the publish method is thread safe.

channel.publish("Hello");

//wait for receiving thread to receive message

latch.await(10, TimeUnit.SECONDS);

//shutdown thread

receiver.dispose();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值