File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Practical Applications of Threads

 
Nick Sharp
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nick Sharp
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47288
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is lots about threading on the net. Start with the Java™ Tutorials.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic