Skip to content

Instantly share code, notes, and snippets.

@mopemope
Created December 10, 2013 04:26
Show Gist options
  • Select an option

  • Save mopemope/7885710 to your computer and use it in GitHub Desktop.

Select an option

Save mopemope/7885710 to your computer and use it in GitHub Desktop.
Simple Fiber park/unpark example
package com.mycompany.fiber;
import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.strands.SuspendableRunnable;
import co.paralleluniverse.strands.channels.Channel;
import co.paralleluniverse.strands.channels.Channels;
public class App
{
public static void main( String[] args )
{
final Channel ch = Channels.newChannel(10);
Fiber fiber1 = new Fiber<Void>(new SuspendableRunnable() {
public void run() throws SuspendExecution, InterruptedException {
System.out.println("1");
Fiber.park();
System.out.println("2");
}
});
Fiber fiber2 = new Fiber<Void>(new SuspendableRunnable() {
public void run() throws SuspendExecution, InterruptedException {
System.out.println("ready suspend");
Fiber.park();
System.out.println("resume!!");
}
});
fiber1.start();
fiber2.start();
fiber2.unpark();
fiber1.unpark();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment