java - can we put thread join method inside synchronized method -


can use thread.join inside synchronized method?

class table{    synchronized void printtable(int n){//synchronized method      for(int i=1;i<=5;i++){        system.out.println(n*i);        try{         thread.join();       }catch(exception e){system.out.println(e);}      }    }   }   

can use thread.join instead of wait?

first of all: it not static method thread.join wont work.
yes can call. no compilation or runtime exceptions please consider below 2 points may don't want want after that. :)
joining thread means 1 waits other end, can safely access result or continue after both have finished jobs.all overloaded versions of join() final , synchronized.
synchronized methods enable simple strategy preventing thread interference , memory consistency errors: if object visible more 1 thread, reads or writes object's variables done through synchronized methods.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -