Re: Java Newbie struggling with threads
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 06/11/04
- Next message: kastis: "RMI server as jar"
- Previous message: Justin Champion: "Jave Wireless Toolkit Error"
- In reply to: Bob Dubery: "Re: Java Newbie struggling with threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 09:26:57 -0500
Bob Dubery wrote:
> Eventually I realised that the only way to do it was to have a common
> object the threads could report to and which could also report back to
> any other thread. Bingo! That worked well - once I spelled synchronize
> with a 'ze' rather than an 'se' - and then the penny dropped all the
> way. There was no other way for it to work.
No other good way, at least. You've got it.
> Coming back to the original problem that was really solved (for me) by
> re-initialising the passed array. Did that really happen because
> arrays are passed by reference?
Yes. (Well, technically, you are passing its reference by value.)
Array instances are objects like any other; when you "pass an array" you
are actually passing its reference.
Array classes are a bit special, but not so as you would notice 99% of
the time. It is sometimes useful to know that Array classes are all
Cloneable and Serializable, and that they expose their clone() methods
with public access. Because arrays are objects you can pass instances
to any method that takes a parameter of type Object; among the more
useful of these are the various methods of the Collections classes.
(I.e. you can store arrays in Lists, Sets, and Maps.)
John Bollinger
jobollin@indiana.edu
- Next message: kastis: "RMI server as jar"
- Previous message: Justin Champion: "Jave Wireless Toolkit Error"
- In reply to: Bob Dubery: "Re: Java Newbie struggling with threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|