• 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

Synchronized and wait+notify... which when?

 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have synchronized way and we have wait+notify way which one to use and when?

Can I say wait+notify would be more efficient when my number of threads increase?

 
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

Akhilesh Trivedi wrote:We have synchronized way and we have wait+notify way which one to use and when?

Can I say wait+notify would be more efficient when my number of threads increase?



It is not exactly "either/or". In fact, the wait() and notify() mechanism depends on synchronization.

Henry
 
Ranch Hand
Posts: 31
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Synchronized only means that one thread can have the intrinsic lock of an object at one time. Wait and notify simple suspend a synchronized method and release the intrinsic lock and then notify tells wait to wake up but only releases the lock when it has finished.
Synchronized when accessing a single variable and wait and notify when many threads as there is also notify all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic