• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

What will Happen if objects wait & notify methode are kept in Thread Class?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case if object Class methods as wait & notify methods are kept in Thread Class, will thread locks still work in the same way it works now?

Will object level & class level locks be still functionally same as of now?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changing the class those methods are associated with will not necesseraly change the mechanism in which they work. It would change the way you would use them. Right now you can use an arbitrary object as a lock and signal, which is very flexible. Associating the wait and notify methods with the Thread class would very much limit how and when you have access to those methods.
 
Kewat Ajay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howsoever I am not satisfied with the answer. My only question about it is that do object level wait & Notify methods will still come in picture if these methods are in Thread class. They may come into picture when Multi threading comes into action. But what play does Object class miss.
Again, if they are not in Object class, what features or rather say 'Power' will Object class miss.
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kewat Ajay wrote:Howsoever I am not satisfied with the answer.



I am not satisfied with the question. What exactly are you proposing? Without knowing that, it's impossible to say what difference it would make.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you put them in the Thread class? They are methods that allow multiple threads to coordinate themselves on a single object. It makes no sense to force that object to be another thread.
 
Kewat Ajay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mathew,
I agree to your point that, it is required to coordinate between multiple threads, but why is it at the Object level?

Why not at the Thread level ??
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kewat Ajay wrote:Mathew,
I agree to your point that, it is required to coordinate between multiple threads, but why is it at the Object level?

Why not at the Thread level ??



Because when they are in the Object class you can have arbitrary objects as locks. You use locks as a means of protecting data, you can have lots of different data, and you can have different locks to protect different data. You can use the object holding the data to protect the data, for example. And you can create inter thread communication when you don't have data. And you can do all of this without needing to know about what thread is executing what code and what other threads are doing.

Why would you put them in the Thread class?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kewat Ajay wrote:Why not at the Thread level ??


Because the coordination is on an object that is shared between multiple threads, not associated with one specific thread.
 
Paul Clapham
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kewat Ajay wrote:Why not at the Thread level ??



Well, as I already said, it's now up to you to explain how exactly how it would work under your proposal. In particular, how would it work differently? What would have to be done to existing code to make it work in the same way if your proposal was accepted?
 
Kewat Ajay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All,

I am now aware about the thread communication which happens at the Object level "locks"..... & not at the Thread level, this clarifies my doubt. Why i asked this question as It was asked to me in one of my java interviews. I wanted to know the reason.

Thanks all for clarification.
 
Master Rancher
Posts: 4321
59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are certainly other ways that these methods cold have been organized, and many of us feel that Object isn't really the best place for these methods. I don't think Thread is either - I think they should be in separate classes entirely, which is the approach taken in newer concurrency constructs such as java.util.concurrent.locks.Lock and java.util.concurrent.Future.

You may be interested in reading some of the many times this discussion has come up in the past. For a start, here is a search for "why wait object notify object" in subject lines in the Threads forum.
 
reply
    Bookmark Topic Watch Topic
  • New Topic