BobbyBorn2L8
BobbyBorn2L8

Reputation: 333

Does calling a thread's method from another thread pause that's thread execution?

Say I call a thread's method from inside another thread as such

public static void main(String[] args)
{
    //do something
    TestThread thread = new TestThread();
    thread.start();
    thread.doSomething();
    //Part A
}

class TestThread extends Thread
{
   public void run()
   {
       //do something
   }

    public void doSomething()
    {
        //Do something
    }
}

Will the program do everything in the doSomething() method before moving onto partA or will it start running the doSomething() method then move straight onto part A?
I'm making an application with a server serving multiple clients and want the server to be able to quickly move through the requests, so it should be once it is sent it moves on rather than waiting for the client to process the instruction.

Upvotes: 1

Views: 43

Answers (1)

Kayaman
Kayaman

Reputation: 73528

No. The main thread will run doSomething() while the thread-thread will be running run() as usual.

Just because doSomething() is in a class that extends Thread doesn't mean that there's anything special about it as a method.

Upvotes: 3

Related Questions