Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » SubMonitor usage in deep recursion chains
SubMonitor usage in deep recursion chains [message #335056] Thu, 19 March 2009 18:34 Go to next message
Aboubacar Kaba is currently offline Aboubacar KabaFriend
Messages: 1
Registered: July 2009
Junior Member
In the API, it is said that the SubMonitor is more efficient in deep
recursion chains.

Does somebody know how to correctly report progress in recursive code
combined with loops and conditions?

Below is an example of what I am doing right now. It has been simplified
to show only the behavior. I dont what I am doing wrong but I don't have
any progress.

void method1(IProgressMonitor monitor){
SubMonitor parent = SubMonitor.convert(monitor, 1);

method2(parent);

if(monitor != null){
monitor.done();
}
}

void method2(SubMonitor monitor){
int count2 = 10;
monitor.setWorkRemaining(count2);
for(int i=0; i<count2; i++){
if(condition){
method3(monitor.newChild(1));
}
monitor.setWorkRemaining(--count2);
}
}

void method3(SubMonitor monitor){
int count3 = 13;
monitor.setWorkRemaining(count3);
for(int i=0; i<count3; i++){
if(condition){
method2(monitor.newChild(1));
}
monitor.setWorkRemaining(--count3);
}
}

This code reports the messages in each method but the progress is not
visible on the bar.

Thanks for any suggestions.
Re: SubMonitor usage in deep recursion chains [message #335080 is a reply to message #335056] Fri, 20 March 2009 14:01 Go to previous message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi Aboubacar,
see below.

Aboubacar Kaba wrote:
> In the API, it is said that the SubMonitor is more efficient in deep
> recursion chains.
>
> Does somebody know how to correctly report progress in recursive code
> combined with loops and conditions?
>
> Below is an example of what I am doing right now. It has been simplified
> to show only the behavior. I dont what I am doing wrong but I don't have
> any progress.
> void method1(IProgressMonitor monitor){
> SubMonitor parent = SubMonitor.convert(monitor, 1);
>
> method2(parent);
You should pass the monitor with newChild(1)
>
> if(monitor != null){
> monitor.done();
> }
Don't call done() on the given monitor. See the javadoc of SubMonitor.

> }
>
> void method2(SubMonitor monitor){
You should create a local SubMonitor as you did above.

> int count2 = 10;
> monitor.setWorkRemaining(count2);
> for(int i=0; i<count2; i++){
> if(condition){
> method3(monitor.newChild(1));
> }
> monitor.setWorkRemaining(--count2);
> }
> }
>
> void method3(SubMonitor monitor){
Same here, you need a local SubMonitor. This way, the calling method
does not have to know how much work is needed.
> int count3 = 13;
> monitor.setWorkRemaining(count3);
> for(int i=0; i<count3; i++){
> if(condition){
> method2(monitor.newChild(1));
> }
> monitor.setWorkRemaining(--count3);
> }
> }
>

Regards, Sebastian
Previous Topic:User management
Next Topic:Disabling plugins in Eclipse 3.4.2
Goto Forum:
  


Current Time: Sat Dec 21 11:57:58 GMT 2024

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

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

Back to the top