Re: concurrency, threads and objects
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 15 Nov 2006 13:09:50 -0000
Tom Forsmo wrote:
Creating only one object and creating a number of threads for that
objects run method, also seems wrong, for two reasons. 1) the object
could then not have any state unless it was to be shared and [...]
That is correct, but it may be the semantics that you want -- if several
threads have to share data for instance. (It's not the typical case, though.)
[...] 2) when
reading the name of the thread all threads are named the same.
The name comes from the instance of Thread, and can be set independently of the
Runnable object that each thread executes.
Creating a number of objects with a thread for each is sort of like
creating many separate programs/processes, it seems like waste of
objects to start with. Why create as many objects as you would create
threads?
I don't know Posix threads, but I assume there is some way that you can ask the
system about a thread once created (is it still running, what groups does it
belong to, and so on). So there is a /something/ there that you can talk
about. In Java a "something" is always represented by an object, so in Java
there is an object (instance of Thread) which stands for each thread.
As an example, a thread couldn't have a name unless there was an object to hold
the name.
-- chris
.
- Follow-Ups:
- Re: concurrency, threads and objects
- From: Tom Forsmo
- Re: concurrency, threads and objects
- References:
- concurrency, threads and objects
- From: Tom Forsmo
- concurrency, threads and objects
- Prev by Date: Re: HashSet and TreeSet
- Next by Date: Re: Increase WinXP/jre CPU usage?
- Previous by thread: concurrency, threads and objects
- Next by thread: Re: concurrency, threads and objects
- Index(es):
Relevant Pages
|