This discussion is archived
2 Replies Latest reply: Feb 5, 2007 6:56 AM by 807606 RSS

What methods in a thread will run parallel?

807606 Newbie
Currently Being Moderated
This might seem like a fairly silly question, but if you have a class that extends Thread and implements runnable, is public void run() the only method of that class that will run parallel to the calling class or will any of the methods in the thread class run in parallel with the calling class?

Interested to know as this is not made so clear in my book...
Jason.
  • 1. Re: What methods in a thread will run parallel?
    807606 Newbie
    Currently Being Moderated
    The run() method is what will run in parallel when you call start() on the thread (also you should rather implement Runnable than extend Thread). If you call any other method in any class from run() they will be run parallel to any other threads.

    Methods and classes are independent from threads of execution.
  • 2. Re: What methods in a thread will run parallel?
    807606 Newbie
    Currently Being Moderated
    Well, it's probably not so clear because, strictly speaking, methods do not run in parallel. When one Thread (Thread A) starts another Thread (Thread B) via the "Thread.start" method, the first method called by "B" is it's "run" method. Thread A continues to run in parallel. Now, if you implement Thread B's run method to invoke another method, on any object, that method will be running in Thread B's execution environment, regardless of where the method is defined - even if the method is defined in the "A" class.

    By the way, you would not need to extend Thread and implement Runnable. You should just be implementing Runnable and creating a new Thread by passing in the Runnable instance.