Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread question

 
Andy Ceponis
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im wrote a small program where i had a group of threads that i placed into an array. They all had to do basically the same thing, as each thread represented a person doing an action. Now i want to expand on that program. I would like to write another class that takes another thread and has that thread interact with one of the threads that is in the array. Now my question is this. For one program, can i have more than one run() method? If not then how would get my new thread to do what i want it to do if it has to run in the same run() method? Im probably overlooking something here, so i apologize for seeming slow.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little puzzled that you say you want the Threads to interact with each other. Do you actually mean call methods on other Thread objects? This is a somewhat strange thing to want to do. It's far more common (and probably more useful) to have all the threads interacting with some shared data items.
Can you clarify a little on what you want to do with these threads?
 
Andy Ceponis
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL, i just re-read my post and even i have no clue what thats supposed to mean. Sorry. I know what i want to ask, but when i type it out it gets all garbled, hehe.
ok, here is some code from a sample i was given to use as an example.

now the run() method there is where the created array of threads execute. But the new thread i want to have wont be in the array. Instead what it should do is pick one of the threads in the array and get information from it. For example when thread 2 is in the 'eat' state, my new thread would want to print that out. Is that more clear?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic