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: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to