How to sequentialize timerexecs in SWT Display [message #1078190] |
Fri, 02 August 2013 12:52  |
Eclipse User |
|
|
|
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 13:00] by Moderator
|
|
|
Re: How to sequentialize timerexecs in SWT Display [message #1082629 is a reply to message #1078190] |
Thu, 08 August 2013 17:13  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.07399 seconds