Click here to Skip to main content
15,943,245 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
class abc extends Thread 
{
    @Override
    public void run ()
    {
        System.out.println(" hello ");    
        System.out.println(" world ");
   
        fg( ) ;
        
        System.out.println(" command ");
        System.out.println(" delete ");
    
        
    }
    
    synchronized void fg ()
    {
        try
        {
            
        Thread.sleep ( 1000 ) ;    
        notify () ;
        
        }
        catch ( InterruptedException e)
        {
            System.out.println(" caught ");
        } 
    }
    
}
public class using_notify 
{
    public static  void main(String[] args) 
    {
    abc w = new abc () ;
w.start () ;    
     
        
        System.out.println(" hi ");

    }
   
}


How will notify() work here when there is no wait method ?
I am deeply confused here . Please help .

What I have tried:

I have run this program on Netbeans .
Posted
Updated 24-May-17 14:02pm

1 solution

If there is no other thread waiting then not much will happen. It tries to notify a waiting thread if available, otherwise it simply does nothing.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900