Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to sequentialize timerexecs in SWT Display(how to sequentialize timerexecs in display)
How to sequentialize timerexecs in SWT Display [message #1078190] Fri, 02 August 2013 16:52 Go to next message
Musical Developer is currently offline Musical DeveloperFriend
Messages: 4
Registered: March 2012
Junior Member
All,

Facing an interesting situation...

timerexec(long delay, Runnable r) in Display suggests that the r will be run *after* delay milliseconds.

I tried a quick piece of code:

int i = 0;
while( i <= 10){
mine mn = new mine(i);

Display.getDefault().timerExec(500, mn);
i++;

}
i++;
mine last = new mine(i);
Display.getDefault().timerExec(500, last);

class mine implements Runnable{

int j = 0;
public mine(int i){
j = i;
}
public void run() {
System.out.println( " mine: " + this + " value: " + j);
}

}
--
This prints out:

value : 12
value : 10
value : 9
value : 8
value : 7
value : 6
value : 5
value : 4
value : 3
value : 2
value : 1
value : 0
--

Questions:

1. I expected the sysouts to be printed in reverse?

2. In my actual program, I do not have control on a set of events which are timerexec'ed at 500 sequentially. (in some other part of program, cannot change code)
I would like to schedule a timerexec at the end of this set...so that I know
for sure that all previous timerexecs have already been executed!

3. Does display timerexec guarantee order amongst "ready runnables" in its timerList

Any help would be appreciated!

[Updated on: Fri, 02 August 2013 17:00]

Report message to a moderator

Re: How to sequentialize timerexecs in SWT Display [message #1082629 is a reply to message #1078190] Thu, 08 August 2013 21:13 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
On 8/2/2013 12:52 PM, Musical Developer wrote:
> 1. I expected the sysouts to be printed in reverse?

Intuitively yes. It looks like Windows' native timer works in 10ms
units, because I was even able to make this happen when timerExec()'ing
the final one for 509ms (up'ing it to 510ms did give the expected ordering).

> 2. In my actual program, I do not have control on a set of events which
> are timerexec'ed at 500 sequentially. (in some other part of program,
> cannot change code)
> I would like to schedule a timerexec at the end of this set...so that I
> know
> for sure that all previous timerexecs have already been executed!

I'm not sure what to suggest here, since Display does not have something
like a getTimers() method. Is there any way for you to receive
notification from the other part of the program of anything that could
be used to infer a timer being set?

> 3. Is there anyway to guarantee order

This is handled natively, so the ordering of timers with functionally
identical expiration times are at the whim of the platform. They would
likely stay consistent on a given platform, but could vary across platforms.

Grant
Previous Topic:How to download SWT examples for Eclipse 4.2.2 ?
Next Topic:Unwanted shrink of table columns
Goto Forum:
  


Current Time: Wed Sep 25 17:06:41 GMT 2024

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

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

Back to the top