Skip to content

grom358/fiber

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Fiber

A cooperative lightweight thread library for Java

Build

Requirements:

  • Java 5 or later
  • Ant

This library depends on Matthias Mann's Continuation library. To download the dependency run:

ant get-deps

Then to build just run ant

ant

Usage

Example of using the Fiber library

import de.matthiasmann.continuations.SuspendExecution;
import fiber.*;

/**
 *
 * @author grom
 */
public class Test {
    static public void main(String[] args) throws Exception {
        FiberScheduler scheduler = new FiberScheduler();
        scheduler.submit(new Fiber() {
            @Override
            public void coExecute() throws SuspendExecution {
                long start = System.currentTimeMillis();
                System.out.println("Hello");
                sleep(2000);
                long elapsed = System.currentTimeMillis() - start;
                System.out.println("World! " + elapsed);
            }
        });
        scheduler.start();
        scheduler.join();
    }
}

In order to build code that uses the Fiber library, the fiber classes need to be instrumented. For example in your Ant build file:

  <taskdef onerror="report" name="continuations"
    classname="de.matthiasmann.continuations.instrument.InstrumentationTask"
    classpath="${lib}/Continuations_full_2013-02-17_03-52.jar:${lib}/asm-all-4.2.jar"/>

  <target name="compile" depends="init">
    <javac srcdir="${src}" destdir="${build}" classpath="${lib}/Continuations_runtime_2013-02-17_03-52.jar"/>
    <continuations verbose="true">
        <fileset dir="${build}"/>
    </continuations>
  </target>

Then to run the compiled class:

java -cp lib/Continuations_runtime_2013-02-17_03-52.jar:lib/Fiber.jar:. Test

Which will output:

Hello
World! 2000

About

A cooperative lightweight thread library for Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages