954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to use wait(); and notify();

I am making a program in which the program assigns a variable to the numbers 1 - 10. I am suppose to use wait and notify. I put them in but I don't know how to assign the variables to the numbers. My code is and could someone tell me how would I assign the vairables

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vairables;

public class Vairables {

    public static void main(String[] args) 
    {
        class IntegerHolder
        {
            String variable = null;
            synchronized void insert(String v)
            {
                while (variable != null)
                {
                    
                    notify();
                    
                    wait();
                }
                variable = v;
                notify();
            }
            
            synchronized int extract()
            {
                while ( variable == null)
                {
                    notify();
                    
                    wait();
                }
                String temp = variable;
                variable = null;
                notify();
                return temp;
            }
        }
    }
}
vishal1949
Light Poster
42 posts since Jul 2011
Reputation Points: 21
Solved Threads: 1
 
how to assign the variables to the numbers


What variables?
Normally you assign values to variables. Can you explain what you mean?

Can you explain what you want this code to do?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: