java - Execute main thread method in child thread -


I have a test example and one of its methods is called dance (). In the main thread, if I call the dance () method inside the hair thread, then what happens? I mean, will that method be executed in the hair thread or the main thread?

  public class testexample {public static zero major (string [] args) {final test test example = new test example (); New thread (new runleball) {@Override Public Zero () {System.out.println ("Hi Child Thread"); Test.dance ();}}). Start (); } Public Zero Dance () {System.out.println ("High Main Thread"); }}    

Try it ...

1. The method is related to the dance class test, for example not the main thread.

2. Whenever a Java application is started, JVM creates a main thread, and holds the main () methods in the bottom of the stack, by making it the entry point, but if you make another thread And are calling a method, then it runs within that newly created thread.

3 its hair thread which will execute dance () method.

See this example below, where I used Thread.currentThread (). GetName ()

  public class test image {public static zero main (string [] algs) {last testxdell exam = new test example (); Thread T = New Thread (New Runnabel) {@ Override Public Wide Run} {System.out.println (Thread. CurrentThread (). GetName ()); Test.dance ();}}); T.setName ("child thread"); T.start (); } Public Zero Dance () {System.out.println (Thread.currentThread (). GetName ()); }}    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -