Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2014, 12:18 AM
Registered User
 
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?
 
Old July 11th, 2017, 03:41 PM
Wrox Author
 
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrollable Control - Alternatives? pagates C# 4 April 5th, 2006 03:26 AM
sql:is-constant Alternatives aowen355 XML 0 June 30th, 2005 06: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 08:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.