commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George Georgovassilis <g.georgovassi...@gmail.com>
Subject Re: [javaflow] how to implement an educational preemptive user-threads package
Date Fri, 22 Jun 2012 17:37:03 GMT
Hi Francis,

I don't think that this would work the way you intend. Each Timer runs 
its own thread which is different than the thread your "payload" code is 
running in. If anything, you would probably have to modify the code at 
compile time (or via a classloader in runtime) to insert suspend() at 
crucial points.

On 06/22/2012 06:00 PM, Francesc Oller wrote:
> 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
>


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


Mime
View raw message