thread quizzes+paradoxes

Q: class SimMessageConsumer extends Thread and overrides run(). In my main() method, i instantiate myThr1 = new SimMessageConsumer() and call myThr1.run(), on which thread does run() run?
A: on the main thread. The real world thread linked to myThr1 is not yet created by VM. That happens when you call myThr1.start().

As stated in another post, a Thread object is a poor handle on a real VM thread.

Q: if MyThread defines a (static or non-static) method m1(), and I call m1() from main(), on which thread does m1() run? Note this is not best practice. Avoid defining any other methods in a Thread derivative.
A: main thread.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s