• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Practical Applications of Threads

 
Nick Sharp
Greenhorn
Posts: 8
  • 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: 34974
379
Eclipse IDE Java VI Editor
  • 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
  • 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: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is lots about threading on the net. Start with the Java™ Tutorials.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic