All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kilim.examples.SimpleTask2 Maven / Gradle / Ivy

Go to download

Coroutines, continuations, fibers, actors and message passing for the JVM

There is a newer version: 2.0.2-jdk7
Show newest version
/* Copyright (c) 2006, Sriram Srinivasan
 *
 * You may distribute this software under the terms of the license 
 * specified in the file "License"
 */

package kilim.examples;

import kilim.ExitMsg;
import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;

/**
 * A slight extension to SimpleTask. This 
 * 
 * [compile] javac -d ./classes SimpleTask2.java
 * [weave]   java kilim.tools.Weave -d ./classes kilim.examples.SimpleTask
 * [run]     java -cp ./classes:./classes:$CLASSPATH  kilim.examples.SimpleTask2
 */
public class SimpleTask2 extends Task {
    static Mailbox mb = new Mailbox();
    static Mailbox exitmb = new Mailbox();
    
    public static void main(String[] args) throws Exception {
        Task t = new SimpleTask2().start();
        t.informOnExit(exitmb);
        mb.putnb("Hello ");
        mb.putnb("World\n");
        mb.putnb("done");
        
        exitmb.getb();
        System.exit(0);
    }

    /**
     * The entry point. mb.get() is a blocking call that yields
     * the thread ("pausable")
     */

    public void execute() throws Pausable{
        while (true) {
            String s = mb.get();
            if (s.equals("done")) break;
            System.out.print(s);
        }
        Task.exit(0); // Strictly optional.
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy