JActor 4.4.0 为定时器增加了 MailboxFactory。
JActor 是一个 Java 的 Actor 模式的实现,经过测试在 i5 CPU 上可支持每秒钟发送超过亿条消息,可能是目前最快的。这相当于是 Scala 的 Actor 的纯 Java 版本。
示例代码:
JAMailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
try {
Mailbox mailbox = mailboxFactory.createMailbox();
JCActor a = new JCActor(mailbox);
(new Include(Greeter.class)).call(a);
JAFuture future = new JAFuture();
String greeting = (new Hi()).send(future, a);
System.out.println(greeting);
} catch (Exception e) {
e.printStackTrace();
} finally {
mailboxFactory.close();
}