[JSch-users] Should Channel.recipient be volatile?
Status: Alpha
Brought to you by:
ymnk
From: Dan S. <da...@sh...> - 2011-02-22 15:18:13
|
Hello All! I am having issues with getting "session is down" and "channel is not opened" JSchExceptions in my code. When looking at the source I noticed the following code: while (this.getRecipient()==-1 && _session.isConnected() && retry>0) { if (timeout>0L) { if ((System.currentTimeMillis()-start)>timeout) { retry=0; continue; } } try { Thread.sleep(50); } catch (Exception ee) {} retry--; } My concern is the getRecipient() call; which simply returns the value of the member variable "recipient". In the case of the above code, the running thread is waiting for the async callback thread to call setRecipient() to signal that the response was received. Since thread A is waiting on the recipient variable to be mutated by thread B, shouldn't recipient be volatile to ensure thread A sees the change? -Dan |