# ScheduledExecution and nUITimerObject

**URL:** <https://techcommunity.softwareag.com/t/scheduledexecution-and-nuitimerobject/100323>\
**Category:** Forum\
**Tags:** mobile\
**Created:** [February 1, 2012, 6:42pm UTC](https://techcommunity.softwareag.com/t/scheduledexecution-and-nuitimerobject/100323 "2012-02-01T18:42:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 1, 2012, 6:42pm UTC](https://techcommunity.softwareag.com/t/scheduledexecution-and-nuitimerobject/100323/1 "2012-02-01T18:42:02Z")

</div>

Hi everyone,  
In our application we need to implement polling and from the samples we were provided the closest one is the UMGDemo. Based on it we have the following code:

```auto
public boolean nUIEventCallback(nUIObject object, int evt_type) {
        switch (object.nuiid) {
     
            case NUIID_ENVIRONMENTS_STATE_TIMER: {
                if (evt_type == EVT_TIMER_COMPLETE) {
                    System.out.println("Tick!");
                    object.tick();
			createComponent();
                    //addTimerObject();
                }
                break;
            }
        }
        
        return true;
}

private void addTimerObject () {
        nUITimerObject timer = new nUITimerObject (NUIID_ENVIRONMENTS_STATE_TIMER, 1000);
        timer.addEventListener(this, true);
        view.add(timer);
}

 public nUIViewDisplay createComponent() {
        view = new nUIViewDisplay(-1);
        addTimerObject();
        
        return view;
}
```

My questions are:

- what is the purpose of the tick method? And is it important to call it everytime?
- Should we recreate the whole view on every TIMER event or it’s OK just to add the nUITimerObject? I guess that the second approach is not prefferable because no one removes the old timers.
- is there an object that fires event on a fixed amount of time (something like TimerTask?)
- if we implement this functionality just starting a new thread and using a flag, is it enough for this flag to be volatile (how will this be cross-compiled?) and we should implement monitor pattern or something like that (again how will this be cross-compiled?) ?

Thanks,  
Nenko

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:01pm UTC](https://techcommunity.softwareag.com/t/scheduledexecution-and-nuitimerobject/100323/2 "2021-04-02T15:01:51Z")

</div>

Closed on April 2, 2021, 3:01pm UTC


