Question

ok so i got this setup: a midlet

    Gui extends Midlet{
        private static Gui instance;

        protected void startApp() {
            Display.getDisplay(this).setCurrent(MyForm.getInstance());
        }

            private static final Logger log = LoggerFactory.getLogger();

        public static Datacheck getInstance() {
            return instance;
        }

        public Gui() {
            // Configure logging
        }

        protected void startApp() {
            instance = this;
            Display.getDisplay(this).setCurrent(MyForm.getInstance());
        }

        protected void pauseApp() {
        }

        protected void destroyApp(boolean bool) {
            // Shutdown Microlog gracefully
            LoggerFactory.shutdown();
            notifyDestroyed();
        }

        public static void log(Level level, String message) {
            log.log(level, message);
        }

        public void requestScreen(Form screen) {
            log.info("request screen called");
            Display.getDisplay(this).setCurrent(screen);
        }
    }

a form

    MyForm extends Form{
        private static MyForm instance;

        public static MyForm getInstance() {
            if (instance == null) {
                instance = new MyForm();
            }
            return instance;
        }

        private Form(){
            //start task
            new Timer().scheduleAtFixedRate(new PollingService(CallsDialog.getInstance()), 0, UPDATE_INTERVAL);

            //add gui elements ....
        }

        private void updateForm() {
            //never gets executed
        }
    }

and a thread

    MyThread implements Runnable{
        private MyForm handle;

        public PollingService(MyForm handle) {
            this.handle = handle;
        }

        public void run() {
            handle.updateForm();
        }
    } 

so the midlet starts, sets its Form to an instance of MyForm then myform creates a new thread this thread should call a function of the myform every 5 seconds

this is a strongly simplified example of the real thing so please, don't change the thread design

now when i execute a method from the "MyForm" class it doesn't execute i don't get any errors

anyone know what I'm doing wrong?

edit changed so there is no thread created (already done by timertask)

Was it helpful?

Solution

1)You don't need to create separate Thread to execute TimerTask. Timer and TimerTask mechanism already contains creation of new thread for every TimerTask execution.

2)Could you provide code that has more reality? There are no MyThread creation in your example, nor start() calling. Sometimes bug is just missing method call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top