×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Question Problem with with my Timer

    Hello, good morning.

    I'm having a problem with my Timer in sending.

    I typed and sent this message using my SMS application: How was your school today?

    The 1st attempt is: 554 milliseconds
    The 2nd attempt is: 577 milliseconds
    The 3rd attempt is: 563 milliseconds
    The 4th attempt is: 549 milliseconds

    My question is: Why is it the timer shows different milliseconds?

    Here's my code:
    Code:
          if(command == send)
          {
              String mno=number.getString();
              if(mno.equals(""))
              {
                  alert = new Alert("Alert");
                  alert.setString("Enter Mobile Number!!!");
                  alert.setTimeout(2000);
                  display.setCurrent(alert);
              }
              else
              {
                  startTime = System.currentTimeMillis();
                  data = file();
                  text = message.getString();
                  StringTokenizer stText = new StringTokenizer(text," ");
                  while(stText.hasMoreTokens())
                  {
                      int found = 0;
                      readWord = stText.nextToken();
                      StringTokenizer st = new StringTokenizer(data,"|");
                      while ((st.hasMoreTokens()) && (found==0))
                      {
                          txtspkWord = st.nextToken();
                          realWord = st.nextToken();
                          if(txtspkWord.equalsIgnoreCase(readWord))
                          {
                              found = 1;
                          }
                      }
                      if(found==1)
                      {
                          newtxt = newtxt + "" + realWord + " ";
                      }
                      else
                      {
                          newtxt = newtxt + "" + readWord + " ";
                      }
                  }
                  temp = newtxt;
                  newtxt = "";
                  capital = capitalize(temp);
                  message = new TextBox ("Message", capital, 960,TextField.ANY);
                  message.addCommand(ok);
                  message.addCommand(clear);
                  message.addCommand(exit);
                  message.setCommandListener(this);
                  alert = new Alert("");
                  alert.setString("Correction took: "+(System.currentTimeMillis() - startTime)+" milliseconds");
                  display.setCurrent(alert,message);
                  String msg=message.getString();
                  try
                  {
                      clientConn=(MessageConnection)Connector.open("sms://"+mno);
                  }
                  catch(Exception e)
                  {
                  }
                  try
                  {
                      TextMessage textmessage = (TextMessage)clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
                      textmessage.setAddress("sms://"+mno);
                      textmessage.setPayloadText(msg);
                      clientConn.send(textmessage);
                  }
                  catch(Exception e)
                  {
                  }
              }
          }
    By they way, I'm using MyPhone QT7 Duo as my testing device.
    Last edited by SHENGTON; 2011-02-15 at 16:11.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Problem with with my Timer

    Hi SHENGTON,

    Go thorough the documentation of the timer class it has the clear explanation of how the scheduling will be done .

    Here is the snippet of the description
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.

    Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Re: Problem with with my Timer

    Hello bhanuchandar.k, good morning.

    Are you talking about the Timer and Timer Task?

    Does "System.currentTimeMillis()" under Timer and Timer Task?

    Because I'm using System.currentTimeMillis() in my code. And I think it is not under in the Timer.

    Correct me if I'm wrong.

    Thanks.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Problem with with my Timer

    Hi SHENGTON,

    Sorry I taught you are doing the scheduling using the timer and timer task. In any application the processing time will vary depending on the what applications are running what is the free memory available , for the application .

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Re: Problem with with my Timer

    Hello bhanuchandar, good evening.

    Thanks for answering my question bhanuchandar. I've got a 2GB memory here in MyPhone QT7 Duo.

    But why is it "System.currentTimeMillis()" does not return the same time? Is there any bugs with "System.currentTimeMillis()"?

    According to this site, it is Time Granularity. What does "Granularity" mean?

    Thanks.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Problem with with my Timer

    Hi SHENGTON ,

    Java does not guarantee real time execution. It means that threads can be suspended because of GC or to yield another thread. In this case the System.currentTimeMillis() granularity may seems to look too big . According to the sun forum . Granularity means I thing the size

    http://bugs.sun.com/bugdatabase/view...bug_id=4423429

Similar Threads

  1. Replies: 5
    Last Post: 2010-05-27, 07:46
  2. Replies: 2
    Last Post: 2010-03-08, 08:03
  3. My first problem with my E51
    By melniciuc.vlad in forum General Development Questions
    Replies: 1
    Last Post: 2009-10-08, 17:01
  4. Problem with my Nokia 5100 with Java books
    By ali780 in forum Mobile Java Games
    Replies: 6
    Last Post: 2008-12-06, 18:58
  5. problem with my application...
    By zikman9 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-08-11, 13:53

Posting Permissions

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