-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage Question: Scheduling tasks within a fiber without spawning a new thread #312
Comments
In that code, it's used to just prevent the actor from dequeueing both message uninterrupted.
Sort of. When you call quasar/quasar-core/src/jdk8/java/co/paralleluniverse/fibers/FiberForkJoinScheduler.java Line 148 in 1a463da
That's it! The state of the timer ultimately is stored in your fiber scheduler instance. You can also create a "timer actor" that sends messages at the right period. |
I'm looking for a way to periodically execute a function inside a ServerActor. This should continue indefinitely until the ServerActor is terminated. In Java, this is typically done by creating a new thread and running a timer. Even in the Quasar tests for Actor, sleep() is used to cause a delay between function calls, which of course creates a new thread.
https://github.com/puniverse/quasar/blob/master/quasar-actors/src/test/java/co/paralleluniverse/actors/ActorTest.java#L185
Coming from the Erlang/Elixir world, I have been happy with an implementation like this, where the GenServer passes itself a message periodically.
https://stackoverflow.com/a/32097971/1289597
My concern is that if I instantiate ServerActors using spawn() rather than spawnThread(), each instance will run in a fiber. However, if I put a sleep() inside one of the methods to handle scheduling, I now have both a fiber and a thread associated with this ServerActor. This seems risky in regard to scaling.
Is there a standard way to implement lightweight task scheduling using fibers in Quasar?
The text was updated successfully, but these errors were encountered: