简体   繁体   English

澄清Java线程的概念

[英]clarification on the concept of Java thread

which is the thread that will begin as soon as the execution of a java program begins? 这是一个java程序执行开始后就会开始的线程? This was asked in an interview for me. 这是在接受我的采访时被问到的。 so can anyone suggest the answer here 所以有人可以在这里提出答案

From Thread API document 来自Thread API文档

When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). 当Java虚拟机启动时,通常会有一个非守护程序线程(通常调用某个指定类的名为main的方法)。

And this thread will be called as main thread. 这个线程将被称为主线程。

The thread which is created when you start is called the main thread . 启动时创建的线程称为main thread It is the one which invokes the main method. 它是调用main方法的那个。

Edit: apparently someone beat me to the answer. 编辑:显然有人打败了我的答案。

The ' main() ' method in Java is referred to the thread that is running, whenever a Java program runs. 无论何时Java程序运行,Java中的' main() '方法都会被称为正在运行的线程。 It calls the main thread because it is the first thread that starts running when a program begins. 它调用主线程,因为它是程序开始时第一个开始运行的线程。 Other threads can be spawned from this main thread. 其他线程可以从这个主线程中生成。 The main thread must be the last thread in the program to end. 主线程必须是程序中要结束的最后一个线程。 When the main thread stops, the program stops running. 当主线程停止时,程序停止运行。

Main thread is created automatically, but it can be controlled by the program by using a Thread object. 主线程是自动创建的,但可以通过使用Thread对象由程序控制。 The Thread object will hold the reference of the main thread with the help of currentThread() method of the Thread class. Thread对象将借助Thread类的currentThread()方法保存主线程的引用。

for more details check this link 有关详细信息,请查看此链接

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

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