i know bit naive question want understand basic working principle behind multi-threading in java. consider following code , executed in main thread , starts execution of worker thread ,defined in class b. want know can b.func1 called , run method of b, executed in parallel or not?
public class { public static void main(string[] args) { b obj = new b(); obj.start(); obj.func1(); } } public class b extends thread { public b() { //constructor } public void run() { while(true) { //do somethings } } public void func1() { //do someotherthings } }
there no magic behind method call. if call method thread, called in same thread. since obj.func1()
called main
, run in main thread. doesn't matter class belongs or whether or not extends thread
.
the new thread starts executing run
. called run , on executed in parallel main
.