• Post Reply Bookmark Topic Watch Topic
  • New Topic

Practical Applications of Threads  RSS feed

 
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?
 
author & internet detective
Marshal
Posts: 37896
594
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?
 
Sheriff
Posts: 57817
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is lots about threading on the net. Start with the Java™ Tutorials.
 
You showed up just in time for the waffles! And this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!