简体   繁体   English

从另一个线程调用线程的方法是否会暂停该线程的执行?

[英]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? 程序在转移到partA之前是否会在doSomething()方法中执行所有操作,还是会开始运行doSomething()方法然后直接转到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. 我正在使用服务于多个客户端的服务器创建一个应用程序,并希望服务器能够快速移动请求,因此应该一旦发送它就会继续运行而不是等待客户端处理指令。

No. The main thread will run doSomething() while the thread -thread will be running run() as usual. 不会。主线程将运行doSomething()thread线程将像往常一样运行run()

Just because doSomething() is in a class that extends Thread doesn't mean that there's anything special about it as a method. 仅仅因为doSomething()在一个扩展Thread的类中并不意味着它作为一种方法有什么特别之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM