Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Scheduler Question

The Jetty scheduler participates in the Jetty component tree / lifecycle.
If it exists in a component that itself is being stopped (even temporarily), then the scheduler will shutdown.
Pointing to a specific line of code isn't really possible, as it's more like if the condition at a high level needs to stop, stop that component (which stops managed components under it which could be a scheduler), until the component is needed again and restarted.
If you use the Jetty Scheduler.schedule() during this state, then nothing happens, there's no ScheduledExecutorService to use, your attempt to schedule results in an empty Task instance that cannot be canceled. (literally a no-op Task per javadoc)

Again, just use the `java.util.ScheduledExecutorService` directly.
Bonus of doing that is you can use a more appropriate scheduling technique for your "runs every 2 seconds" use case, instead of rescheduling after every execution.
Plus you can control the lifecycle of it yourself.
And you can interrogate the state of the `ScheduledExecutorService` to find out the queue/task details.

See: 
- Joakim

On Thu, Aug 15, 2024 at 9:04 AM Josh Spiegel <joshlakewg@xxxxxxxxx> wrote:
Thank you - I will certainly take your suggestion. 

If feasible, could you point me to code or documentation that shows the specific circumstances in which Jetty would cancel my task?  I only want to know so that I can judge if this is indeed what has been happening in my case or not and gain confidence in the fix for this elusive issue...

Thanks again,
Josh




On Wed, Aug 14, 2024 at 1:18 PM Joakim Erdfelt <joakim.erdfelt@xxxxxxxxx> wrote:
The org.eclipse.jetty.util.thread.Scheduler is an interface from back in the Java versions that didn't have a scheduler of its own (we're talking back in the Java 1.4 days!).
Anymore, the implementation in Jetty is just a `java.util.concurrent.ScheduledExecutorService` under the covers.

You would probably be better off just using the JVM class directly, and not be subject to the side effects of how Jetty uses its own scheduler. (example: the idle timeout behaviors and low resource behaviors can cancel tasks, or reduce the timing, or even increase the timing, depending on where the scheduler is)

 - Joakim

On Wed, Aug 14, 2024 at 1:30 PM Josh Spiegel via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Hi,

We are using the scheduler to schedule a background task that runs every 2 seconds:

    connector.getScheduler().schedule(this, 2000, TimeUnit.MILLISECONDS);

When it wakes up, it processes some log data and then schedules itself to run again in 2 seconds.

Very rarely, for a cause and reason we can't explain, the rescheduling does not happen and the background process never runs again.  We've caught any possible Throwable in the task execution and log any possible exception that might occur.  The logs are empty, the task just stops.  The thread pool is nowhere near exhausted when this happens.

This happens so rarely that it is very difficult to debug. 

Any ideas what might cause something like this?

Thanks,
Josh
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top