Ordering

N

nialltimpson

Hey, simple question for yee all,

Im writeing a threaded program but am a little confused in which order the
methods are called, I know it goes from start() to run() but I also have a
init() so when exactlywould this be called beforw or after start(),

Sorry for my ignorance towards this topic,

niall.
 
H

HK

nialltimpson said:
Hey, simple question for yee all,

Im writeing a threaded program but am a little confused in which order the
methods are called, I know it goes from start() to run() but I also have a
init() so when exactlywould this be called beforw or after start(),

I remember that I was similarly confused when I looked
at it the first time. Consider the run() method defined
in interface Runnable as something which is *not*
intimately related to threaded operation. It just defines
an object which can do something meaningful when
its run() is called.

The start() method of Thread, on the other hand, is the
time at which indeed at new thread of operations is
branched off the main trunk. I guess it does some
bookkeeping and finally calls run() of an enclosed
Runnable object or of the Thread itself.

If your Runnable has an init() method, I guess you want
to call it before forking off the new thread of operations
to set up things before the real work can start. This,
however, depends strongly on what you actually want to
do. I could as well imagine an init() which is called
from run().

Harald.
 
N

nialltimpson

Thanks, very much for you reply, I appreceate it and im glad im not the
only one baffled by this. I think I have a good just of what is going on,
now all I have to do is understand what im going to do!!

Thank again

Niall.
 
T

Thomas G. Marshall

nialltimpson coughed up:
Thanks, very much for you reply, I appreceate it and im glad im not
the only one baffled by this. I think I have a good just of what is
going on, now all I have to do is understand what im going to do!!

Thank again

Niall.


Put in the foremost section of your mind that if you haven't been coding in
multiple threads for years that you are most definitely going to do many
things wrong. There is no "good just (sic) of what is going on" regarding
threads, until you've been at it for awhile.

And most senior engineers are convinced that they've got a great handle on
it, when they don't.

How do I know this? I used to be contracted to fix multi-threaded java code
and have seen many of the same simple mistakes, even by senior guys.
 
D

Dotty

nialltimpson said:
Hey, simple question for yee all,

Im writeing a threaded program but am a little confused in which order the
methods are called, I know it goes from start() to run() but I also have a
init() so when exactlywould this be called beforw or after start(),

Sorry for my ignorance towards this topic,

niall.

If I remember right, your browser calls init() if it is an applet,
and you are responsible for calling init() if it is an application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top