Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Use ModelJobs to update UI
Use ModelJobs to update UI [message #1864818] Thu, 11 April 2024 00:24 Go to next message
Pr Nico is currently offline Pr NicoFriend
Messages: 15
Registered: February 2021
Junior Member
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 #1864821 is a reply to message #1864818] Thu, 11 April 2024 08:44 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 207
Registered: November 2010
Senior Member
That code looks quite good to me. What exactly do you mean by "the form doesn't appear as expected"?

Note that the "waitFor()" call blocks the current thread until the form is closed, i.e. from perspective of the scheduler, that job has not been completed yet. If you need to open a form every X seconds no matter if the previous form has been closed, you can simply remove the waitFor() call.

In some cases it can make sense to use normal jobs to schedule the model job. That way, the triggered jobs will complete fast and don't risk overlapping with the next scheduled execution. Something like this:

Jobs.schedule(() -> { // <-- async job (repeating execution)
  LOG.info("Job started");
  ModelJobs.schedule(() -> { // <-- model job (one time execution)
    LOG.info("Form opened");
    MyForm form = new MyForm();
    form.start();
    form.waitFor();
    LOG.info("Form closed");
  }, ModelJobs.newInput(ClientRunContexts.copyCurrent()));
  LOG.info("Job ended");
}, Jobs.newInput()
    .withRunContext(ClientRunContexts.copyCurrent())
    .withExecutionTrigger(...) // <-- repeating schedule
);
Re: Use ModelJobs to update UI [message #1865067 is a reply to message #1864821] Thu, 25 April 2024 13:23 Go to previous messageGo to next message
Mr Robot is currently offline Mr RobotFriend
Messages: 71
Registered: March 2020
Member
Hello, what do you mean "in some cases"?

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?
Re: Use ModelJobs to update UI [message #1865157 is a reply to message #1865067] Sat, 27 April 2024 06:44 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 100
Registered: February 2021
Senior Member
@MrRobot

Can you check to see if the job stopped as a result of an exception and if the exception was properly handled? I remember I had some logout/login cycle issues too because of an unhandled exception.

Cheers,

JD

[Updated on: Sat, 27 April 2024 06:46]

Report message to a moderator

Re: Use ModelJobs to update UI [message #1865250 is a reply to message #1865067] Mon, 29 April 2024 14:22 Go to previous message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 207
Registered: November 2010
Senior Member
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.
Previous Topic:Know server session Id from Client session id or vice versa
Next Topic:Simple tab area moves down opening a view in BenchLayoutData
Goto Forum:
  


Current Time: Wed May 08 10:02:41 GMT 2024

Powered by FUDForum. Page generated in 0.02861 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top