About Question com.enthuware.ets.scjp.v6.2.362 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
patpat09
Posts: 2
Joined: Mon Nov 11, 2013 3:16 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.362 :

Post by patpat09 »

There is a small mistake in the explanation:

Code snip:

Code: Select all

public class TestClass
{
  static StringBuffer sb1 = new StringBuffer();
  static StringBuffer sb2 = new StringBuffer();
  public static void main(String[] args)
  {
      new Thread
      (
         new Runnable()
         {
            public void run()
            {
                synchronized(sb1)
                {
                    sb1.append("X");
                    synchronized(sb2)
                    {
                      sb2.append("Y");
                    }
                }
                System.out.println(sb1);
            }
         }
      ).start();
      new Thread
      (
         new Runnable()
         {
            public void run()
            {
                synchronized(sb2)
                {
                   sb1.append("Y"); //<- appends Y to sb1, not "appends Y to sb2"
                    synchronized(sb1)
                    {
                      sb2.append("X"); // <- appends X to sb2
                    }
                }
               System.out.println(sb2);
            }
         }
      ).start();
  }
}

Explanation:
[...] Second thread acquires the lock of sb2 and appends Y to sb2.[...]
I think it must correct to:

admin
Site Admin
Posts: 10062
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.362 :

Post by admin »

Fixed.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests