Return-Path: X-Original-To: apmail-hama-dev-archive@www.apache.org Delivered-To: apmail-hama-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DEEB410AAE for ; Wed, 2 Sep 2015 10:44:45 +0000 (UTC) Received: (qmail 70176 invoked by uid 500); 2 Sep 2015 10:44:45 -0000 Delivered-To: apmail-hama-dev-archive@hama.apache.org Received: (qmail 70144 invoked by uid 500); 2 Sep 2015 10:44:45 -0000 Mailing-List: contact dev-help@hama.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hama.apache.org Delivered-To: mailing list dev@hama.apache.org Received: (qmail 70133 invoked by uid 99); 2 Sep 2015 10:44:45 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2015 10:44:45 +0000 Date: Wed, 2 Sep 2015 10:44:45 +0000 (UTC) From: "Edward J. Yoon (JIRA)" To: dev@hama.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HAMA-972) Synchronization on local variable MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HAMA-972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14727159#comment-14727159 ] Edward J. Yoon commented on HAMA-972: ------------------------------------- Hi, I think you can find the answer from here - http://stackoverflow.com/questions/2779484/why-must-wait-always-be-in-synchronized-block > Synchronization on local variable > ---------------------------------- > > Key: HAMA-972 > URL: https://issues.apache.org/jira/browse/HAMA-972 > Project: Hama > Issue Type: Bug > Components: bsp core > Reporter: JongYoon Lim > Priority: Minor > > I'm not sure that the synchronization of the following code is proper. > In the code, it uses the *call variable* as a lock. But it's a local variable. So whenever this function is called, the lock is changed. I think this is a bug... What do you think..? Is there anything that I'm missing..? > {code} > // Client.java > public Writable call(Writable param, ConnectionId remoteId) > throws InterruptedException, IOException { > Call call = new Call(param); > Connection connection = getConnection(remoteId, call); > connection.sendParam(call); // send the parameter > boolean interrupted = false; > synchronized (call) { > int callFailCount = 0; > while (!call.done) { > try { > call.wait(1000); // wait for the result > // prevent client hang from response error > if (callFailCount++ == IPC_CLIENT_CONNECT_MAX_RETRIES_DEFAULT) > break; > } catch (InterruptedException ie) { > interrupted = true; > } > } > if (interrupted) { > // set the interrupt flag now that we are done waiting > Thread.currentThread().interrupt(); > } > if (call.error != null) { > if (call.error instanceof RemoteException) { > call.error.fillInStackTrace(); > throw call.error; > } else { // local exception > // use the connection because it will reflect an ip change, > // unlike > // the remoteId > throw wrapException(connection.getRemoteAddress(), call.error); > } > } else { > return call.value; > } > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)