Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: wait() and notify()

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default wait() and notify()

    i m new to java ... i have read many aticles on net regarding wait() and notify() but unable to get ..can you please make me understand about these two method with example


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: wait() and notify()

    Reading articles is the first step, perhaps 10% of the process of learning. Us giving you more to read doesn't make that 10% any bigger. The other 80 - 90% is putting what you've read into practice, right and wrong, through coding. Show us what you've tried and ask any questions you have about the results.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: wait() and notify()

    hi sir can you provide me a best site(url) for java Thread from which i gain more ..

  4. #4
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: wait() and notify()

    Quote Originally Posted by gautammuktsar@gmail.com View Post
    hi sir can you provide me a best site(url) for java Thread from which i gain more ..
    A good start is Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

    Some more you can get from articles like Java 101: Understanding Java threads, Part 1: Introducing threads and runnables | JavaWorld

    If you want to go more more deeper, buy "Java Concurrency in Practice", by Addison-Wesley Professional.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: wait() and notify()

    wait()-- It is used to send the running thread into waiting mode, means stand by mode.

    notify()-- It is used to send waiting thread into "Ready State Queue", means it will put the waiting thread into "Ready Queue"

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: wait() and notify()

    @chsvravikumar@gmail.com: Please check the most recent response date on threads. If a thread has been dormant for ~> 1 month, it's dead, the OP has moved on and probably doesn't care anymore.

    However, if you have a gem of a good idea that you want to share with someone trying to do the same thing who may happen by someday, then by all means add it. (In this case, your post is not an example of such a gem.)

  7. #7

    Default Re: wait() and notify()

    wait( ) tells the calling thread to give up the monitor and go to sleep until some other
    thread enters the same monitor and calls notify( ).

    notify( ) wakes up the first thread that called wait( ) on the same object.

  8. #8
    Junior Member
    Join Date
    Mar 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: wait() and notify()

    Both the methods are used to block the thread for particular time interval until a specific condition is met. The necessity is that you need to ensure that any calls to wait() or notify() are within a synchronized area of code.
    wait() : Causes current thread to release the lock and wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
    notify() : Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: wait() and notify()

    Three years old thread closed.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. wait(); and notify();
    By tenacious23cb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 14th, 2013, 04:36 PM
  2. Simple multithreading using wait and notify
    By fgstat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 27th, 2013, 02:20 AM
  3. Help wanted using wait() and notify()
    By sandramo in forum Java Theory & Questions
    Replies: 7
    Last Post: March 29th, 2013, 12:19 PM
  4. wait(), sleep() and notify()
    By evthim in forum Threads
    Replies: 3
    Last Post: October 30th, 2012, 11:37 AM
  5. How to notify() and proceed past wait()
    By kernel_klink in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 21st, 2012, 07:40 PM