how to update/refresh Progress View from a long-running non-UI Job in eclipse rcp - eclipse

i have a long-running non-UI Job with a number of sub-tasks. each sub-task updates caption for the Job's progress entry in the Progress View via IProgressMonitor.subTask(some-caption). the Job goes through three sub-tasks before it contributes to the UI in its fourth sub-task (via Display.syncExec() of course) by creating a new IEditorPart instance. the problem is that those initial three sub-tasks are never reflected in the Job's progress entry in the Progress View. in fact, the Job progress entry never actually appears in the Progress View until fourth sub-task. this, of course, creates a problem for a user who is left to wonder if anything is even happening. my guess is that once the Job starts, the vm thread "broker" (sorry, not well versed in this matter) never gets a chance to switch from a non-UI Job thread to the UI thread until the former actually makes a call to the latter via Display.syncExec(). my only solution at this point is to put Job thread to sleep for about half a second right after each sub-task kicks in, thereby allowing UI thread to take over long enough to update Progress View. and while this has worked most of the time, i still get instances here and there where the Porgress View still remains empty until fourth sub-task, leading me to believe that my solution is not of a robust kind. hence, i am looking for a robust one. thank you for your time!
EDIT: example code
Job job = new Job("multipleTasks") {
public IStatus run(IProgressMonitor monitor) {
monitor.beginTask("multiple tasks", IProgressMonitor.UNKNOWN);
monitor.subTask("task1");
monitor.worked(1);
try { Thread.sleep(1000); } catch (Exception e) { }
monitor.subTask("task2");
monitor.worked(1);
try { Thread.sleep(1000); } catch (Exception e) { }
monitor.subTask("task3");
monitor.worked(1);
try { Thread.sleep(1000); } catch (Exception e) { }
monitor.done();
return Status.OK_STATUS;
}
};
job.schedule();

Related

Eclipse Jobs stay in the Progress View after returning an OK status

I have a an Eclipse Job class similar to the following:
public class MyCustomJob extends Job {
#Override
protected IStatus run(IProgressMonitor monitor) {
MyObject.blockingMethod();
return Status.OK_STATUS;
}
}
When I execute this job and it exits correctly, the bottom-right where the progress is listed while it is running still shows the name of the now completed job, but without any progress bar.
If I double click in the region where the name of the job still is, the Progress View opens as expected, but shows that the job has finished. If I click the "x" to clear the job, it disappears from the view, but if I close the view and reopen it, it comes right back.
How can I remove the name of the job from the bottom-right of the display and guarantee that if I clear the Finished job from the Progress View that is actually being dismissed?
Check the return path for any async UI execs that could affect status. Changing
from:
Platform.getDefault().asyncExec(runnable)
to
Platform.getDefault().syncExec(runnable)
fixed this issue

Unity3d Parse FindAsync method freezes UI

I'm running a simple Parse FindAsync method as show below (on Unity3d):
Task queryTask = query.FindAsync();
Debug.Log("Start");
Thread.Sleep(5000);
Debug.Log("Middle");
while (!queryTask.IsCompleted) {
Debug.Log("Waiting");
Thread.Sleep(1);
}
Debug.Log("Finished");
I'm running this method on a separate thread and I put a load circle on UI. My load freezes (+- 1 second) somewhere in the middle of the Thread.sleep method. It's look like when findAsync finishes the process it freezes the UI until it complete their job. Is there anything I could do?
Ps: This works perfectly on editor, the problem is on Android devices.
Ps2: I'm running parse 1.4.1
Ps3: I already tried the continueWith method, but the same problem happens.
IEnumerator RunSomeLongLastingTask () {
Task queryTask = query.FindAsync();
Debug.Log("Start");
//Thread.Sleep(5000); //Replace with below call
yield WaitForSeconds(5); //Try this
Debug.Log("Middle");
while (!queryTask.IsCompleted) {
Debug.Log("Waiting");
//Thread.Sleep(1);
yield WaitForSeconds(0.001f);
}
Debug.Log("Finished");
}
To call this function, use:
StartCoroutine(RunSomeLongLastingTask());
Making the thread sleep might not be a good idea, mainly because the number of threads available is different on each device.
Unity as a built-in scheduler that uses coroutines, so it is better to use it.
IEnumerator RunSomeLongLastingTask()
{
Task queryTask = query.FindAsync();
while (!queryTask.IsCompleted)
{
Debug.Log("Waiting"); // consider removing this log because it also impact performance
yield return null; // wait until next frame
}
}
Now, one possible issue is if your task take too much CPU, then the UI will still not be responsive. If possible, try to give a lower priority to this task.

Disabling busy cursor for eclipse Job

This code does what I need, with the exception that there is a quick switch between the normal cursor, and the busy cursor happening extremely fast.
/* this code is run inside the createPartControl(Composite parent) method of a ViewPart */
Job job = new Job("refreshing")
{
#Override
protected IStatus run(IProgressMonitor monitor)
{
while (data.isReading())
{
Display.getDefault().syncExec(new Runnable()
{
#Override
public void run()
{
treeViewer.setInput(DataView.this.dataModel.getArray());
}
});
}
return Status.OK_STATUS;
}
};
job.schedule();
So is there a way of disabling the busy cursor of a Job in eclipse?
Also, could this happen because the Job is called in a GUI class?
Call
job.setSystem(true);
before you schedule the job. From the JavaDoc:
Sets whether or not this job is a system job. System jobs are
typically not revealed to users in any UI presentation of jobs. Other
than their UI presentation, system jobs act exactly like other jobs.
If this value is not explicitly set, jobs are treated as non-system
jobs. This method must be called before the job is scheduled.
However I think the busy cursor is coming from the BusyIndicator.showWhile call in AbstractTreeViewer.createChildren which the tree setInput will call. I don't think you can do anything about.

Eclipse Progress View is not refreshing when running many jobs

I've problem with running big number of concurrent Jobs in my Eclipse RCP application. When I start 100 Jobs (like the one bellow), they execute normally but after they are finished they are still visible in Progress View for about 10 seconds. I would like Progress View to clear Jobs immediately after they are finished. If I start less Jobs (eg. 10) Progress View refreshes it self immediately.
class MyJob extends Job
{
public MyJob(String name) {
super(name);
}
public IStatus run(IProgressMonitor monitor){
//SOME EXPENSIVE COMPUTATIONS
BigInteger bigint = new BigInteger("0");
for ( int i=0 ; i<100 ; i++ ) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
bigint = bigint.add(new BigInteger(Integer.toString(i)));
}
monitor.done();
System.out.println(new Random().nextInt());
return new Status(IStatus.OK, "foo", "OK");
}
}
each job is scheduled as a separate thread and in case there are lots of them locking/synchronization/thread management mechanisms take some overhead. for example some internal Eclipse Jobs code explicitly puts progress-bar-feedback mechanism into sleep for 250ms. such solutions probably pile up into long delays.
anyway having 100 entries in Progress View is not user firendly. I'd suggest grouping those jobs with Job.setProgressGroup(). perhaps having less entries in the view will cover up slow responsiveness.
In a case like this, I'd say it's better to allocate your own Threads than to use Jobs. Your 100 Jobs are going to start using the Job Threads that would be used to do Workbench maintenance. Allocating your own Threads means the Jobs Thread pool doesn't grow to the max value and stay there.
I'd have one Job that starts your Threads and reports progress to the Progress View. You could use SubMonitor to split the main IProgressMonitor into 100 so each of the Thread/Runnable pairs you start can report progress back to the main Job.

Eclipse Debugging is being executed or not

During debugging an Application ,
Assume taht a line of execution is taking a lot of time , how can we know that Eclipse still in the process of Debugging ??
For example assume that the method client.submitOrder() shown below is taking 5 mins to get executed ??
Is there any Indication shown anywhere that eclipse is still running that method ??
public void test()
{
try
{
ServiceResponse response = client.submitOrder(request);
System.out.println("Doen")
}
catch(Exception e)
{
e.printStackTrace();
}
}
Assuming that you have started the application in Debug mode and if you are in the Debug View, the thread executing the method shows that the method it is in Stepping state.
I don't have a screenshot for this at the moment, but will try to upload one soon.