• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wait method doesn't working.

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why method wait() doesn't work ?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dawid Skrzypczynski wrote:



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.

Henry
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How should I interrupt the thread?

I will add only that I would like to resume later this thread
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Henry
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question too difficult for "beginning". Moving thread.
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote something like this:

This code doesn't working
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


change to ...

 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replay Chris but after changing program still doesn't work properly.
I tried to do it slightly differently but the program still doesn't work. I have one question.

1) Why in line 53 the program show me that they are three threads. I think that should be two. The main thread and t thread.

I really don't understand why after changing the value of variable pause the Thread is not blocked...

 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I discovered that this line:

induces new thread but how can i control this particular thread ?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dawid Skrzypczynski wrote:Ok I discovered that this line:

induces new thread but how can i control this particular thread ?



Back to my original response -- the only safe way to do this is cooperatively. Obviously, if you don't have access to change the code in this new thread, then you can't.

Henry
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Henry
 
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic