Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 3rd Edition
This is the forum to discuss the Wrox book Programming Interviews Exposed: Secrets to Landing Your Next Job, 3rd Edition by John Mongan, Noah Kindler, Eric Giguere; ISBN: 978-1-118-26136-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 3rd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 6th, 2014, 12:18 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Difference for alternatives to evade busy waiting

Hi all,
In the book two different approaches to evade busy waiting are shown:

Code:
Object theLock = new Object();
synchronized( theLock ){
Thread task = new TheTask( theLock );
task.start();
try {
theLock.wait();
}
catch( InterruptedException e ){
.... // do something if interrupted
}
}
and
Code:
Thread task = new TheTask();
synchronized( task ){
task.start();
try {
task.wait();
}
catch( InterruptedException e ){
.... // do something if interrupted
}
}

Are these two completely interchangeable or are there instances when one should be used over the other?
Reply With Quote
  #2 (permalink)  
Old July 11th, 2017, 04:41 PM
Wrox Author
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These are functionally equivalent. You can use any shared object for the lock. It's a matter of style as to what is most convenient and most clearly communicates the intent of what you're doing.

John
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrollable Control - Alternatives? pagates C# 4 April 5th, 2006 04:26 AM
sql:is-constant Alternatives aowen355 XML 0 June 30th, 2005 07:52 AM
Alternatives to Crystal. mburley Crystal Reports 1 February 1st, 2005 06:47 PM
Why "Waiting for..." Gringosperto Dreamweaver (all versions) 1 December 7th, 2004 04:30 PM
Querystring Alternatives lukemedway_uk Classic ASP Basics 1 October 7th, 2003 09:45 AM



All times are GMT -4. The time now is 03:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.