Use ModelJobs to update UI [message #1864818] |
Wed, 10 April 2024 20:24  |
Eclipse User |
|
|
|
Hello,
I'm working on an application that needs to periodically display a form to the user, but I'm encountering an issue where the form doesn't appear as expected
I believe it is a thread issue but I can't find much example on good practise for it, any help is appreciated
private void checkReminders() {
MyForm form = new AppointmentForm();
form.startNew();
form.waitFor();
}
private void startModelJobs() {
ModelJobs.schedule(() -> {
checkReminders();
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withName("ModelJobs")
.withRunContext(ClientRunContexts.copyCurrent())
.withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(10, TimeUnit.SECONDS).withSchedule(
SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).repeatForever())));
}
}
|
|
|
|
|
|
Re: Use ModelJobs to update UI [message #1865250 is a reply to message #1865067] |
Mon, 29 April 2024 10:22  |
Eclipse User |
|
|
|
Quote:what do you mean "in some cases"?
As a general rule, the ModelJob should be as short-lived as possible, because while it is running, the UI is blocked for the user. Any substantial "work" that doesn't require interaction with the UI model should be run as a normal job.
Quote:
We have problem with model jobs, sometimes they just stop working.
User needs to logout/login.
We cannot find any reference when this is happening.
Do you think ModelJobs inside Jobs would help?
At least add some log output to your job, see my example above. This should give you a hint where it "stops working".
Generally, Jobs don't just stop, but they can fail with an error. As JD suggested, you should check if any exceptions occurred. If your logger has not been misconfigured, you should see them in your logfile. Note that there are some types of errors that are not visible by default (e.g. ThreadInterruptedError). You can either increase the log level so see them or catch them manually with a try-catch. You can also customize the error handler for each job, see the JavaDoc for JobInput.withExceptionHandling(), although this is rarely necessary. If you use the pattern with two nested jobs, you can catch any error from the inner job while resuming the outer job normally.
|
|
|
Powered by
FUDForum. Page generated in 0.09957 seconds