Results 1 to 2 of 2
  1. #1
    Azuki is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default What will happen when other threads use the following code?

    Multiple objects of MyClass (given below) are used in a program that uses multiple Threads to create new integer count.
    What will happen when other threads use the following code?

    Java Code:
    class MyClass
    {
    	static private int myCount = 0;
    	int yourNumber;
    
    	private static synchronized int nextCount()
    	{
    		return ++myCount;
    	}
    
    	public void getYourNumber()
    	{
    		yourNumber = nextCount();
    	}
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,543
    Rep Power
    5

    Default Re: What will happen when other threads use the following code?

    Why not just generate some other threads and see what happens?

    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2012, 11:57 AM
  2. what had happen to this?
    By mathidioticz in forum New To Java
    Replies: 3
    Last Post: 01-27-2012, 12:09 PM
  3. What happen to the code?
    By mathidioticz in forum New To Java
    Replies: 6
    Last Post: 01-21-2012, 05:56 PM
  4. what happen if an object set to null
    By SaYuNaRa in forum New To Java
    Replies: 5
    Last Post: 04-17-2008, 04:15 AM
  5. To happen of ActionErrors to ActionMessage
    By Eric in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •