Re: concurrency, threads and objects



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



.



Relevant Pages

  • Re: concurrency, threads and objects
    ... objects run method, also seems wrong, for two reasons. ... In Java a "something" is always represented by an object, ... If I use 100 threads, I would create 100 ClassA objects, which means I would have 100 ClassA objects and 100 Thread objects. ... Sort of like starting 100 separate programs/processes. ...
    (comp.lang.java.programmer)
  • Re: HardBound and SoftBound
    ... and neither C# nor Java come close to C/C++. ... from time to time when changes are required or for speed reasons. ... speeds comparable with the C++ C# compiler from MS. ... In practice RISC wasn't such a big change, ...
    (comp.arch)
  • Re: Java and .NET (no Flames Pls)
    ... I like .NET over Java for a couple of reasons. ... ingrained concept in some developers mind that all MS products suck (not ... Visual Studio has superior support for Web Services. ...
    (microsoft.public.dotnet.framework)
  • Re: (1/2 OT) Reasons to begin with .Net
    ... If you aren't familiar with .NET (or Java or C++ etc) then I honestly would be very suspicious of any controls you attempt to market. ... The market for VB6 controls is effectively dead today.NET is continuing going from strength to strength. ... But if you are looking at the booming market sectors, then .Net and Java are still the two leaders. ... I want to clarify to myself the reasons to write programs in .Net and the reasons not to do it. ...
    (microsoft.public.vb.general.discussion)
  • Re: Book question on threads
    ... > Reading a Java certification book, ... > "Which of these are plausible reasons why a thread might be alive, ... Sun Certified Programmer for the Java 2 Platform ... Sun Certified Developer for the Java 2 Platform ...
    (comp.lang.java.programmer)