aspose file tools*
The moose likes Beginning Java and the fly likes Practical Applications of Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Practical Applications of Threads" Watch "Practical Applications of Threads" New topic
Author

Practical Applications of Threads

Nick Sharp
Greenhorn

Joined: Jul 14, 2009
Posts: 8
I've been learning about threads and I understand the concept behind them and the theory (or at least I think I do), but how to apply them in code still confuses me a little. Can anyone point me to some examples of how to use threads in different situations?

Here's a specific question:

Should I make a thread that instantiates an object that does stuff, or do should I make the thread itself do the stuff with its runnable? Does it matter aside from slight performance differences?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30540
    
150

Nick Sharp wrote:Here's a specific question:

Should I make a thread that instantiates an object that does stuff, or do should I make the thread itself do the stuff with its runnable? Does it matter aside from slight performance differences?

It matters from a design perspective. It's clearer if a thread is limited in what it does and any significant logic resides elsewhere. Which makes it easier to reuse that logic.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nick Sharp
Greenhorn

Joined: Jul 14, 2009
Posts: 8
So if a thread creates an object, anything that object does will take its turn in the JVM through the thread, correct? Could I call on an object created by a thread from outside the thread?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
There is lots about threading on the net. Start with the Java™ Tutorials.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Practical Applications of Threads