commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesc Oller <francesc.ol...@upc.edu>
Subject [javaflow] how to implement an educational preemptive user-threads package
Date Fri, 22 Jun 2012 16:00:06 GMT
Hi, I'm experimenting with javaflow and wonder wether it's possible to
develop a preemptive quantum-based scheduler out of javaflow. The idea
would be to execute Continuation.suspend() inside a SIGALRM handler,
which would fire when thread quantum is elapsed. A first, basic example
is:

import org.apache.commons.javaflow.*;
import java.util.*;
import sun.misc.Signal;
import sun.misc.SignalHandler;

class Continuations {
  final static int T = 2000;
  public static void main(String[] args) {
    /*
    second alternative, use Timer instead of SIGALRM
    new Timer().scheduleAtFixedRate(new TimerTask() {
      public void run() {
        Continuation.suspend();
      }},
      T,
      T
    );*/
    Signal.handle(new Signal("ALRM"), new SignalHandler () {
      public void handle(Signal sig) {
        Continuation.suspend();
      }
    });
    Continuation c = Continuation.startWith(new Runnable() {
      public void run() {
        while (true) {
          System.out.println("running!");
          Signal.raise(new Signal("ALRM"));
        }
      }
    });
    System.out.println("finishing!");
  }
}

Can this idea be made to work?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message