Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12616
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail |
|---|---|
| From | Martin Gregorie <martin@address-in-sig.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Strange Socket problem |
| Date | Sat, 3 Mar 2012 02:13:19 +0000 (UTC) |
| Organization | UK Free Software Network |
| Lines | 58 |
| Message-ID | <jirunv$rd7$1@localhost.localdomain> (permalink) |
| References | <jiojsa$5ol$1@dont-email.me> <4f512b27$0$26687$65785112@news.neostrada.pl> <jirjpg$rkb$1@news.albasani.net> <jirlma$bfm$1@dont-email.me> <jirmv1$1gj$1@news.albasani.net> <jirrgc$d64$1@dont-email.me> |
| NNTP-Posting-Host | 84.45.235.129 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | localhost.localdomain 1330740799 28071 84.45.235.129 (3 Mar 2012 02:13:19 GMT) |
| X-Complaints-To | usenet@localhost.localdomain |
| NNTP-Posting-Date | Sat, 3 Mar 2012 02:13:19 +0000 (UTC) |
| User-Agent | Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) |
| Xref | csiph.com comp.lang.java.programmer:12616 |
Show key headers only | View raw
On Fri, 02 Mar 2012 17:18:04 -0800, Knute Johnson wrote:
> On 3/2/2012 4:00 PM, Lew wrote:
>> Knute Johnson wrote:
>>> The volatiles exist because the methods that access them can be called
>>> from other threads. I could have synchronized the start() stop()
>>> methods but not easily the socket variable in the run() method. I
>>> thought it was cleaner to just use volatile.
>>
>> I see a problem right there.
>>
>>> public void disconnect() {
>>> if (isConnected())
>>> if (socket != null)
>>> try {
>>> socket.close();
>>> } catch (IOException ioe) {
>>> ioe.printStackTrace();
>>> }
>>> }
>>
>> Since these are controlled by separate synchronization (different
>> 'volatile' variables) there's a race condition trying to work with both
>> at once.
>
> I don't think so.
>
>> Also, 'socket' can become 'null' between the check for not 'null' and
>> the 'close()' call.
>
> Only if I set it to null and I don't. That is there so that if the
> Socket doesn't make the first connection when disconnect() is called
> that I won't get a NPE.
>
>> You need to synchronize with 'synchronized' or other strong mechanism.
>
> I don't think so and here's why; isConnected only gets modified by one
> thread and read by another, socket is only modified by one thread and
> read by another. In the disconnect() method, as soon as isConnected()
> is called, isConnected the volatile variable is read and that would make
> socket current even if it weren't volatile which it is but I didn't want
> to rely on side effects in case I changed code somewhere.
>
> Anyway, disconnect() isn't getting called in this situation so it's not
> causing my problem.
>
> I really appreciate everybody looking at this. I've got a couple of
> ideas of where to code some traps and I'll have to put those in one
> night and see what happens.
new Socket() can return null (it says, but not why) but I don't think
that is happening or you'd have seen an NPE.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 11:49 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-01 20:59 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 13:30 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-01 22:54 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:32 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-03 09:08 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:48 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-01 14:08 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:48 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-02 08:33 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:29 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-03 09:33 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:55 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-03 20:06 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 21:02 -0800
Re: Strange Socket problem "John B. Matthews" <nospam@nospam.invalid> - 2012-03-05 00:00 -0500
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-05 09:44 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-01 22:15 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:43 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:01 +0000
Reiteration: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:51 -0800
Re: Reiteration: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:02 +0000
Re: Strange Socket problem x <x@x.x> - 2012-03-02 21:18 +0100
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-02 15:06 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:38 -0800
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-02 16:00 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 17:18 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:13 +0000
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-03 08:41 +0000
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 18:26 +0000
Re: Strange Socket problem x <x@x.x> - 2012-03-03 11:32 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:59 -0800
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-03 23:21 -0800
Re: Strange Socket problem x <x@x.x> - 2012-03-03 10:59 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:08 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:33 -0800
Re: Strange Socket problem Paka Small <paka-en@tumia.org> - 2012-03-03 03:32 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:00 -0800
Re: Strange Socket problem x <x@x.x> - 2012-03-03 12:45 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:02 -0800
csiph-web