×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    30

    Nokia S40 series handling timer + timertask

    Hi,

    I have a problem in implementing a timer and timer task with an httpconnection in order to achieve a timeout for the connection if in case it doesn't receive a response. It was successfully implemented in s60 series such as nokia 5230,nokia E63,Nokia 5233,.

    But the same implementation of timer and timer task normally is not working in S40 series as i tried in Nokia 2730 classic,Nokia X2 .

    It throws a illegalStateException: task already scheduled or canceled.

    So can any one help me!


    Thanks in advance.
    Janardhan.B

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Nokia S40 series handling timer + timertask

    IllegalStateException, as stated in the documentation, is raised when you call certain methods that can only be called at some times. Given your error message, it would be that you call the schedule method twice. The difference in behaviour is probably due to the difference multithreading handling between S40 and S60.
    Try to find out where the scheduling is called, and how it can be called twice.

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Nokia S40 series handling timer + timertask

    I tend to avoid Timer and TimerTask. From experience, they can be troublesome, behaving differently on different devices.

    I prefer to use Thread and Runnable.

    Graham.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    30

    Re: Nokia S40 series handling timer + timertask

    Thanks for the repoly guys,

    Graham, but how can you implement a httpconnection timeout with just only using Thread and Runnable and without using a timer&timertask.

    Thanks in advance.
    Janardhan.B

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Nokia S40 series handling timer + timertask

    If you can do it with a Timer, you can do it with a Thread.

    For example...

    Code:
    public interface TimeoutListener {
        public void timeout(Object o);
    }
    Code:
    public class TimeoutWatchdog implements Runnable {
        private long time;
        private TimeoutListener listener;
        private Object object;
        private volatile boolean stopped;
    
        public TimeoutWatchDog(long millis, TimeoutListener l, Object o) {
            time = millis;
            listener = l;
            object = o;
        }
    
        public void start() {
            Thread t = new Thread(this);
            t.start();
        }
    
        public void stop() {
            stopped = true;
        }
    
        public void run() {
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                // ignore
            }
            if (!stopped && listener != null) {
                listener.timeout(object);
            }
        }
    }
    Graham.

Similar Threads

  1. differents between timer, timertask and thread??
    By -Icaro- in forum Mobile Java General
    Replies: 6
    Last Post: 2009-05-20, 18:03
  2. HTTP Session Handling on Nokia S40
    By mogreenik in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2008-07-23, 16:02
  3. General Info about PNG file format - Timer and TimerTask
    By nodevelop in forum Mobile Java General
    Replies: 2
    Last Post: 2005-01-27, 18:31
  4. Nokia Series 40 Timer Accuracy
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 33
    Last Post: 2003-09-12, 09:27
  5. Timer and TimerTask on 3650
    By raffaelesergi in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-21, 10:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •