IsAlive method:
The IsAlive method () function is to determine whether the current thread is active.
The active state is a thread that is started and has not been terminated, such as running or ready to run.
Public classIsalivethreadextendsThread { PublicIsalivethread () {System.out.println ("Begin"); System.out.println ("Thread.CurrentThread (). GetName ():" +Thread.CurrentThread (). GetName ()); System.out.println ("Thread.CurrentThread (). IsAlive ():" +Thread.CurrentThread (). isAlive ()); System.out.println ("This.getname ():" + This. GetName ()); System.out.println ("This.isalive ():" + This. isAlive ()); System.out.println ("End"); } @Override Public voidrun () {System.out.println ("Run Begin"); System.out.println ("Thread.CurrentThread (). GetName ():" +Thread.CurrentThread (). GetName ()); System.out.println ("Thread.CurrentThread (). IsAlive ():" +Thread.CurrentThread (). isAlive ()); System.out.println ("This.getname ():" + This. GetName ()); System.out.println ("This.isalive ():" + This. isAlive ()); System.out.println ("Run End"); }} Public classThreadrunmain { Public Static voidMain (string[] args) {testisalivethread (); } Public Static voidTestisalivethread () {Isalivethread ist=NewIsalivethread (); Thread th=NewThread (IST); System.out.println ("Main begin th isAlive =" +th.isalive ()); Th.start (); System.out.println ("Main end th isAlive =" +th.isalive ()); }}
Operation Result:
Thread IsAlive method of Java Learning note