Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2005

Tip: Looking for answers? Try searching our database.

What is run() mean?

Thread view: 
boki - 11 Mar 2005 01:07 GMT
Hi, Group,

A rookie new to J2SE ( no java program experience )

What is run() mean? It seems run with no caller, the same trigge like
startApp(), pause(), destroy()?

Thank you very mcuh!

Best regards,
Boki.
Tor Iver Wilhelmsen - 11 Mar 2005 08:12 GMT
> What is run() mean? It seems run with no caller, the same trigge like
> startApp(), pause(), destroy()?

A lot of methods you write - like main(String[]) - are called by a
"framework" or some other external trigger that you don't write. run()
is one of therese, esp. in Runnable, where a Thread object is supposed
to do the call to run().
Boki - 21 Mar 2005 17:19 GMT
I got it,
but, why my run() always run once?

why not a loop??

strange....

Best regards,
Boki.

"Tor Iver Wilhelmsen" <tor.iver.wilhelmsen@broadpark.no>
???????:u4qfi37xd.fsf@broadpark.no...

>> What is run() mean? It seems run with no caller, the same trigge like
>> startApp(), pause(), destroy()?
[quoted text clipped - 3 lines]
> is one of therese, esp. in Runnable, where a Thread object is supposed
> to do the call to run().
Thomas Schodt - 21 Mar 2005 17:37 GMT
> I got it,
> but, why my run() always run once?
>
> why not a loop??

If you need a loop, you should put it in the run() method.

class Worker implements Runnable {
    private boolean active = true;
    private Thread me;
    public void run() {
        me = Thread.currentThread();
        while(active) {
            // do your never-ending processing here
        }
    }
    public terminate() {
        active = false;
        me.interrupt(); // works for sleep()
    }
}

class Fubar {
    Worker w = new Worker();
    new Thread(w).start();
    ...
    w.terminate();
}
boki - 22 Mar 2005 01:55 GMT
Hi Thomas,
         Thanks a lot.

Best regards,
Boki.

> > I got it,
> > but, why my run() always run once?
[quoted text clipped - 24 lines]
>     w.terminate();
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.