Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Quick Questions on Syntax

Reply
Thread Tools

Quick Questions on Syntax

 
 
Arne Vajhøj
Guest
Posts: n/a
 
      05-27-2008
Tom Anderson wrote:
> On Mon, 26 May 2008, Arne Vajhøj wrote:
>> Lord Zoltar wrote:
>>> Umm I think you are talking about the lines that look like:
>>> (new Thread(new Producer(drop))).start();
>>> ...correct?
>>> To me it looks like they are creating a new Thread object and calling
>>> start() on it, without assigning the new object to a variable. I am
>>> pretty sure this is legal, but I don't think you can reference the
>>> object that gets created here after it's been created (since you have
>>> nothing to reference it by) so I'm not sure what the point of this way
>>> of doing thins is. This syntax is not something I see very often, and
>>> I'm not sure I see a point to it, except maybe for brevity for simple
>>> examples.
>>> Maybe someone who has a non-trivial example of the way to use this can
>>> correct me? It might be an accepted practice for working with threads
>>> in Java, although it's been a while since I've done Java threads (and
>>> I never saw this syntax back then).

>>
>> It is most certainly valid syntax.
>>
>> The problem is that it is not possible to join on the started thread
>> (or in other ways interact with it).
>>
>> If that is not needed, then it can be used.
>>
>> I don't think it is a construct used in many serious programs.

>
> Maybe there's no need to interact with the threads from the thread which
> creates them. That wouldn't be that surprising. In that case, it's
> cleaner not to keep a reference.


It can happen.

But I do find wild running threads to be somewhat suspicious code.

If you need to start something, then you will usually want to know
if it is done.

> Bear in mind that the threads share a reference to the Drop object, and
> it's straightforward for them to interact with each other through that.


Not as straightforward as having a ref to the Thread.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding quick-release to a non-quick-release tripod head ste7esmith@hotmail.com Digital Photography 4 11-20-2006 03:19 PM
Quick question, hopefully quick answer. ~misfit~ NZ Computing 114 01-06-2005 01:36 PM
Quick Question Quick Answer JKop C++ 11 05-24-2004 09:46 PM
Quick Restore for a Compaq not so quick! Croos Bustamunky Computer Support 2 05-15-2004 04:17 AM
PanasonicBQ390 "quick" charger - How quick? Ol' Bab Digital Photography 1 01-17-2004 06:54 AM



Advertisments