I have a method that starts a thread, and I want to have the method block until the thread finishes its setup stage, or else face a race condition.
I know I want to use wait notify, but I don’t know how to own the monitor and so on.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Move your “setup stage” out of
run()and into aninit()method.Edit: Or as @Buhb noted in the comments below, just put it in the constructor. Years of C++ makes old habits die hard.