Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12640

Re: Strange Socket problem

Path csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <nospam@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: Strange Socket problem
Date Sat, 03 Mar 2012 18:08:13 -0800
Organization A noiseless patient Spider
Lines 79
Message-ID <jiuiqd$oil$1@dont-email.me> (permalink)
References <jiojsa$5ol$1@dont-email.me> <4f512b27$0$26687$65785112@news.neostrada.pl> <jirjpg$rkb$1@news.albasani.net> <4f51eba2$0$1255$65785112@news.neostrada.pl>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 4 Mar 2012 02:08:13 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="25173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19P7aeayZ2EjRu8HqbX8NsL"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
In-Reply-To <4f51eba2$0$1255$65785112@news.neostrada.pl>
Cancel-Lock sha1:hKy+hJ+8Yc2bLoFhvnCY1V/mwl4=
Xref csiph.com comp.lang.java.programmer:12640

Show key headers only | View raw


On 3/3/2012 1:59 AM, x wrote:
> Lew pisze:
>> On 03/02/2012 12:18 PM, x wrote:
>>> Knute Johnson pisze:
>>>> I'm having a problem in some production code that I can't figure out.
>>>
>>> Can you please describe the usage of your class ?
>>>
>>> I'm rather puzzled about having a Thread object inside a Runnable.
>>> Your class
>>
>> The issue would be what's used inside the 'run()' method, not just
>> what fields the class has.
>>
>> I agree that the 'thread' variable's scope is wrong - it should be
>> local to 'start()', not an instance member. But at the moment that's
>> not causing any outright harm.
>>
>>> makes it is extremely easy to have TWO threads accessing private
>>> fields, this
>>> is rarely a good idea. (yes, I have recreated it :-)
>>
>> His class spawns one thread per instance. The main thread doesn't use
>> the mutable fields. The only common access of note is the 'runFlag'
>> mechanism, which is bog-standard in his code. The 'thread' member is
>> not referenced within 'run()'. I'm not sure why all his other instance
>> variables are 'volatile', but at first blush I don't see a problem
>> with his synchronization safety.
>>
>> You need to be specific about the trouble you claim you found. Show us
>> where, because I don't see danger coming from the areas you cited.
>
> Consider the following scenario:
>
> SportsWinClient swc = new SportsWinClient();
> swc.start();
> new Thread(swc).start();
>
> (this exact code is unlikely to be present, but if the swc variable is
> passed around, someone, in a code far far away, may start the swc in a
> new thread. Simply because it's a Runnable.)
>
> That is why I'm asking about the usage scenario.
>
>>> What exactly is the point of the public start() method? I must say it
>>> looks
>>> suspicious to me.
>>
>> It's also bog standard, and bog simple. Its purpose is to start the
>> socket thread.
>
> Is it standard... well, I'm not sure. As far as I know, the most typical
> thing to do would be to create a Runnable object (containing ONLY the
> task logic), and a separate Thread object:
>
> Runnable myRunnable = new MyRunnable(...);
> Threat t = new Thread(myRunnable);
> t.start();
>
>
>
>>
>> public class Client
>> {
>> public static void main(String[] args)
>> {
>> new SportsWinClient().start();
>> }
>> }
>>

I'm not sure what your argument is.  It is easy enough either way to 
create or start numerous examples.  I don't and I won't and your 
scenario wouldn't prevent that either.  And if the Thread is started 
more than once it throws and exception.

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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