• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this really multi-threaded?

 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is a program that only has one explicit thread running multithreaded? The reason I ask is that in the book Java after hours there are two programs that are similar and are called multithreaded. In one the thread controls a set amount of fish and moves them around the screen, but the Fish class does not implement runnable or extend thread. Is this really multi-threaded and why?

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aquarium implements Runnable (instead of extending Thread) and starts a new Thread near the end of its constructor. There will be other housekeeping threads, like the GUI event processing thread and the garbage collector, so yes, this code is multithreaded.
[ June 13, 2006: Message edited by: Joe Ess ]
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks, so any java program with a GUI can be considered multithreaded?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every Java program has several threads. Something has to run the garbage collector.
Saying something is "multithreaded" implies that the programmer has utilized threads to make the program run smoother, do multiple tasks simultaneously or improve performance.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have always thought of multi-threaded to mean that the program explicity uses multiple threads, not counting the ones in the background that the programmer has little to no control of, and this program was labeled multi-threaded seemed a bit confusing from my understanding of the term.

I was also confused a tad, because the fish were labeled as seperate threads(not by the book or its author), and that does not seem like the case here.

Anyway thanks a lot. I am having a blast modifying the code, I have added a pop up to control the amount of fish, added 15 fish .gif's that get loaded randomly, threw in a dolphin, shark, crab if the user wants them. Next up is the ability to choose different backgrounds, fish, allow the shark to feast on the fish, and maybe throw in a fisherman. Good fun and terrific book.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic