File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Is this really multi-threaded? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Is this really multi-threaded?" Watch "Is this really multi-threaded?" New topic
Author

Is this really multi-threaded?

Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
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?



"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
ok thanks, so any java program with a GUI can be considered multithreaded?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

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

Joined: Jan 03, 2006
Posts: 490
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is this really multi-threaded?