Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and Arrays  RSS feed

 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey yo,

I have just started to delve into the idea of threads with java and was doing quite well until I came to this problem.

How does a child thread, modify the array variable of its parent class?

.eg


How can I make the "//fibn(n-1)+fibn(n-2);" line directly modify the array?

I have looked around the net for about an hour now and am still no closer to the answer.

Any help would be great (also sorry if this is in the wrong area)
[ August 28, 2007: Message edited by: Peter Shipway ]
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Don't get confused between Java access rules (among classes and packages) and parent-child thread relationship. Think of these two as simple classes.

Now, the case would be simply to access the array declared in one class from another one.

How about passing the array reference to constructor of class 'fibthread' (pls consider naming the classes with proper semantics) and storing it in some private property (just like the argument 'n') to access it later?

Regards,

- Aditya Jha

[ August 28, 2007: Message edited by: Aditya N Jha ]
[ August 28, 2007: Message edited by: Aditya N Jha ]
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.g. make the thread an inner class, note all I have done is move a } ...


 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I meant to say just make the thread class an inner class, just a one line change. The top line of my post got lost somewhere.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!