Dawid Skrzypczynski wrote:
Why method wait() doesn't work ?
The wait method causes the current thread to wait for notification. It doesn't cause the thread, represented by the thread object that you are using to wait. Notice that it is a method of the object class, and not the thread class.
As for why the instance is needed, it is related to how condition variables work.
Maybe, but the method is deprecated. And the reason it is deprecated is... under certain conditions it can suspend the thread, along with the JVM locks that it owns, and cause the whole JVM to no longer work.
Dawid Skrzypczynski wrote:How should I interrupt the thread?
I will add only that I would like to resume later this thread
The only safe way to do this is cooperatively. There needs to be communication between the two threads -- maybe using flags, wait/notify, and/or interrupts. The targeted thread needs to monitor requests and be coded to pause and restart as needed.
First of all don't use someBoolean == false, instead use !someBoolean.
The "problem" is that the two threads each hold a copy of the pauze variable (disregarding the fact that you use the lock only in one place).
Their are a couple of ways of synchronize those. I would advise you to read this. Multi-threaded programming without the proper knowledge of threading can and will lead to some horrible bugs.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Dawid Skrzypczynski wrote:Thank you all for your reply.
If i can't blocked the thread induced by the constructor Player that the only solution is use the suspend and resume methods.
In the past, I noticed that debbuggers and IDEs are the most likely culprits to break with suspend and resume. Now that it has been deprecated for so long, I would not be surprised if other setups may break.
But, if you have no choice, you have no choice. Hope it works.