java - Why main thread waits for another thread to finish before proceed? -


the problem facing in complex java application boils down following: main thread not proceeds until sub-thread not finished, although thought should. code exemplifies problem shown below:

public class threadtest {          static class mythread extends thread{             public void run(){                 for(double = 0; i<1; i+=0.01){                     system.out.println(math.pow(math.pi,math.e)*100.0*i-234.0);                 }             }         }          public static void main(string[] args){             (new mythread()).run();             system.out.println("main thread");         }     } 

when run program, output mythread first (independently how many steps in cycle), , message main thread. idea of creating threads execute code asynchronously, here observe sync behavour. miss?

thanks in advance!

when call run(), calling run() method in current thread!. in same manner if called other method object.

if want new thread call run(), need call start() on thread.

try

new mythread().start(); 

one way prove step through program in debugger, show there 1 thread.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -