Lightweight threads for Java, with message passing, nio, http and scheduling support.
Kilim is composed of 2 primary components:
Together, these facilities allow for simple concurrency and can scale to millions of concurrent tasks
Code can be woven:
kilim.tools.Weaver
kilim.tools.Kilim com.yourcompany.yourclass
if (kilim.tools.Kilim.trampoline(false,args)) return;
at the start of main()Please see docs/manual.txt and docs/kilim_ecoop08.pdf for a brief
introduction.
src/kilim/examples
contains some simple examplessrc/kilim/bench
contains some performance benchmarkskj/src/main/java/KilimJetty.java
shows integrating with jetty asynckilim/src/main/java/KilimHello.java
shows the built-in kilim web server (which in addition to doing async connections also does async io)for an example of a project that uses kilim (with the trampoline for runtime weaving) see the
battle royale demo in this repository.
clone this repository, and from that directory execute mvn package exec:java -Dexec.mainClass=kilim.demo.Battle
java.util.concurrent.Future<V>
is an interface that can represents the result of an asynchronous computation.
kilim pre-dates java futures, and uses a slightly different api, but kilim supports the same notion, ie to block until an async computation finishes:
kilim.Task.joinb()
blocks until a Task
completeskilim.Task.isDone()
returns true if this Task
completedkilim.Mailbox.getb()
is also similarthese methods allow synchronizing threads with async computations. however, the real power of kilim
is in enabling communication between async computations. for this, use the join()
and get()
methods
which are Pausable
for an example of a project that uses kilim, see
the kilim jetty demo in this repository
pom.xml
specifies kilim as both a dependency and a plugin for ahead-of-time weavingthe dependency:
<dependency>
<groupId>org.db4j</groupId>
<artifactId>kilim</artifactId>
<version>2.0.1</version>
</dependency>
weaving with the kilim plugin:
<plugin>
<groupId>org.db4j</groupId>
<artifactId>kilim</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<goals><goal>weave</goal></goals>
</execution>
</executions>
</plugin>
java.lang.Runnable: once a java.lang.Task starts running, it takes over the thread until it returns
kilim.Continuation: like java.lang.Runnable, but can yield (relinquish control of the thread) while preserving state. It’s caller must arrange to resume it at some appropriate time. Used for event-driven state machines where the event loop knows when to resume. The programmer is in charge of the event loop.
kilim.Task: like kilim.Continuation, but specifies a reason that it yields, and a scheduler automatically resumes it when the reason is no longer true. Typically used for a system of communicating state machines that communicate using Mailboxes. Releases the programmer from the job of mapping fibers to thread and of managing an event loop and the delivery of events.
kilim.Pausable: a hypothetical exception used to declare intent. a method that declares this to be thrown will trigger the weaver
kilim.Mailbox: a queue with Pausable methods that cause the calling Task method to yield when an operation would otherwise block and to resume automatically when the Mailbox because available for reading or writing
kilim.Fiber: the structure that stores the Continuation (and Task) state
java 8, 11 and 12 are the recommended platforms, but 7, 8, 9, and 10 are regularly tested, and in theory java 6 could probably still be made to work without too much work
java 8, java 9, java 11, java 12 and java 13-ea:
org.db4j : kilim : 2.0.2
java 7:
JAVA_HOME=path/to/java7 ant clean weave jar
demos/java7
for usage examples2.0.1-jdk7
java 9:
java 10:
java.lang.NoClassDefFoundError
when attempting to load a woven fiber-less lambdaFiber dummy
Fiber
argument should not be accessed in the lambdaPausable
lambda, call the default method2.0.0-28-jdk10
interface Lambda {
void execute(Fiber fiber) throws Pausable, Exception;
default void execute() throws Pausable, Exception {}
}
static void dummy() throws Pausable, Exception {
Lambda lambda = dummy -> {
Task.sleep(1000);
System.out.println("hello world");
};
lambda.execute();
}
java 11:
-javaagent
(fixed in java 12)demos/java11
lambdas:
jshell:
demos/jshell
for an example of automatic weavingJEP-330 single file source invocation
demos/java11
for an exampleKilim.trampoline
in main to enable weaving public static void main(String[] args) {
if (kilim.tools.Kilim.trampoline(new Object() {},false,args)) return;
...
modules:
module-info.java
is provided
Project Loom:
summary:
mvn initialize
(but any pom-based mvn command should work too)and cleaner
to delete the copied jarsmvn package && ant jar
simple:
mvn install
build with tests:
ant clean testjit test jar doc
details:
mvn install:install-file -DpomFile=pom.xml -Dfile=$(target/kilim*.jar) -Dsources=target/sources.jar -Djavadoc=target/javadoc.jar
public support:
nqzero is currently the primary maintainer.
he’s focused on making Kilim easy to use and reliable and is actively using Kilim
Sriram is the original author (in 2006 !) and deserves a great deal of thanks for his excellent work.
He continues to provide guidance on kilim and is especially interested in theory and performance,
but is not actively using kilim today.
He can be reached at kilim at malhar.net
a number of companies (or their employees) appear to have been using Kilim recently and have contributed
Kilim v2.0
This software is released under an MIT-style license (please see the
License file). Unless otherwise noted, all files in this distribution are
offered under these terms, and files that explicitly refer to the “MIT License”
refer to this license