• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Practical Applications of Threads

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is lots about threading on the net. Start with the Java™ Tutorials.
 
reply
    Bookmark Topic Watch Topic
  • New Topic