this.getstate_Java线程类Thread.State getState()方法(带示例)
this.getstate
線程類(lèi)Thread.State getState() (Thread Class Thread.State getState())
This method is available in package java.lang.Thread.getState().
軟件包java.lang.Thread.getState()中提供了此方法。
This method is used to return the state of this thread.
此方法用于返回此線程的狀態(tài)。
When we execute a thread so there are various states for normal execution of the thread [States of the Thread like, start, ready, running, waiting, blocked, terminate].
當(dāng)我們執(zhí)行一個(gè)線程時(shí),有多種狀態(tài)可以正常執(zhí)行該線程[線程的狀態(tài),如啟動(dòng),就緒,運(yùn)行,等待,阻塞,終止]。
This method is not final so we can override this method in child class.
此方法不是最終方法,因此我們可以在子類(lèi)中重寫(xiě)此方法。
The return type of this method is Thread.State so it returns the state of this thread
此方法的返回類(lèi)型為T(mén)hread.State,因此它返回此線程的狀態(tài)。
This method does not raise any exception.
此方法不會(huì)引發(fā)任何異常。
Syntax:
句法:
Thread.State getState(){}Parameter(s):
參數(shù):
We don't pass any object as a parameter in the method of the Thread.
我們不會(huì)在Thread方法中將任何對(duì)象作為參數(shù)傳遞。
Return value:
返回值:
The return type of this method is Thread.State, it returns the state of this thread.
該方法的返回類(lèi)型為T(mén)hread.State ,它返回此線程的狀態(tài)。
Java程序演示getState()方法的示例 (Java program to demonstrate example of getState() method)
/* We will use Thread class methods so we are importing the package but it is not mandate because it is imported by default */import java.lang.Thread;class GetThreadState extends Thread {// Override run() of Thread classpublic void run() {// By using getState() method is used to return // the state of this threadSystem.out.println("The state of this thread is : " + Thread.currentThread().getState());/* This is another way of writing the above statementThread.State th_state = Thread.currentThread().getState();System.out.println("The state of this thread is : "+th_state);*/}public static void main(String[] args) {// Creating an object of GetThreadState classGetThreadState gt_state = new GetThreadState();// We are setting the name of the thread GetThreadStategt_state.setName("GetThreadState");// Calling start() method with GetThreadState class // object of Thread class/gt_state.start();// By using getName() method to return the name of this // thread [GetThreadState]System.out.println("The name of this thread is " + " " + gt_state.getName());} }Output
輸出量
E:\Programs>javac GetThreadState.javaE:\Programs>java GetThreadState The name of this thread is GetThreadState The state of this thread is : RUNNABLE翻譯自: https://www.includehelp.com/java/thread-class-thread-state-getstate-method-with-example.aspx
this.getstate
總結(jié)
以上是生活随笔為你收集整理的this.getstate_Java线程类Thread.State getState()方法(带示例)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: html页面授权码,spring boo
- 下一篇: ntce服务器不稳定,当心!你的教师资格