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
ETS User

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

Post by ETS User »

Just small remark
Explanation: This is a complex question. Consider the following situation :
First thread acquires the lock of sb1. It appends X to sb1. Just after that the CPU stops this thread and start the second thread. (Note that first thread still has the lock of sb1). Second thread acquires the lock of sb2 and appends Y to sb2. Now it tries to acquire the lock for sb1. But its lock is already acquired by first thread so the second thread has to wait.
but in code for second thread

Code: Select all

      new Thread
      (
         new Runnable()
         {
            public void run()
            {
                synchronized(sb2)
                {
                    sb1.append("Y"); // <-- here
                    synchronized(sb1)
"Y" is appended to sb1 not to sb2

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

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

Post by admin »

You are right. It should be sb1 in the explanation. This has now been fixed.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests