×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    22

    about using thread on midlet

    helo.i write following code.

    Code:
    public void setTop(int t)
        {
            top=t;
           // sonuc=Integer.toString(top);
       
        }
    
    public class DoSomething implements Runnable {
            public DoSomething()
            {
                top=0;
              }
            public void run(){
                for(int i=0;i<20;i++)
                {
                    top+=i;
                }
                //f.append(Integer.toString(top));
                setTop(top);
            }
       }
        
        public void commandAction(Command c,Displayable d)
        {
            if(c==exit)
                notifyDestroyed();
            else if(c==islem1)
            {
                DoSomething ds=new DoSomething();
                
                Thread t=new Thread(ds);
                f.append(Integer.toString(top));
                t.run();//t.start();
                //f.append(sonuc);
                f.append(Integer.toString(top));
                
            }
        }
    my problem is:if i use *"t.run()"* it write 190 on midlet screen,but i use *t.start();* it writes 0.
    Code:
    public DoSomething()
      {
        top=0;//this line
      }
    when i remove *top=0* from above code t.start() and t.run() writes 190 on screen. i don't understand the wrong.
    Is there any difference between run and start methods?Thanks...

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: about using thread on midlet

    Hi,
    Well, mark that while you are calling the t.run();
    Then can you imaging that what is happening is that it would be just treated as a simple method and not the thread's run()..

    However when you call the start() then in turn the internally run() will be called then it now treated as thread's run()..

    Thats all about the differences between the two approaches..
    As far as the returned values are concern then it depends upon the code..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: about using thread on midlet

    When you will call run() method it will not create thread. So it will be called by simple function. When you will call start() new thread will be start so it will be multithreading. From this description you will understand the different between your output.

  4. #4
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: about using thread on midlet

    Just to add a link about concurrency. Good to check that if you have doubts about how threads work, very important topic in J2ME

    http://java.sun.com/docs/books/tutor...rocthread.html
    :Ruben

Similar Threads

  1. S60 5th ed emulator startup failed
    By hony in forum Symbian Tools & SDKs
    Replies: 8
    Last Post: 2009-08-11, 21:12
  2. emulator startup failed
    By hony in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-11-11, 06:07
  3. Pushregistry, Security Alert after signing the midlet?
    By juppi in forum Mobile Java Networking & Messaging & Security
    Replies: 15
    Last Post: 2007-08-08, 11:04
  4. Error on "emulator"
    By zhang2008 in forum Symbian
    Replies: 2
    Last Post: 2006-10-08, 16:55
  5. Thread
    By Kalderas in forum Symbian
    Replies: 4
    Last Post: 2003-08-14, 15:02

Posting Permissions

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