puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.56k stars 575 forks source link

how to park multiple times in a fuction at different place ? #342

Closed LingXi1420 closed 3 years ago

LingXi1420 commented 3 years ago

I just want to implement an aync mehod in one thread, and the method may pack and unpack many times , but once I call pack at the 2nd time, it will re-call the full method twice, I just need it to run from laster park block,

public class SuspendTest implements SuspendableRunnable { public void run() throws SuspendExecution { System.out.println("Thread name:" + Thread.currentThread().getName() + " run"); System.out.println("Thread name:" + Thread.currentThread().getName() + " before park"); Strand.park(this.obj); System.out.println("Thread name:" + Thread.currentThread().getName() + " ==== unparked "); System.out.println("Thread name:" + Thread.currentThread().getName() + " before park"); Strand.park(this.obj); System.out.println("Thread name:" + Thread.currentThread().getName() + " ==== unparked "); } }

it print : Thread name:ForkJoinPool-default-fiber-pool-worker-5 run Thread name:ForkJoinPool-default-fiber-pool-worker-5 before park Thread name:ForkJoinPool-default-fiber-pool-worker-5 run Thread name:ForkJoinPool-default-fiber-pool-worker-5 before park Thread name:ForkJoinPool-default-fiber-pool-worker-5 ==== unparked Thread name:ForkJoinPool-default-fiber-pool-worker-5 before park