Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Threads  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is a Thread?I know it is used for multiple process execution!
But how would one define it?How does it really help in Simultaneous execution of code?
I just want to understand the basics!
 
author
Sheriff
Posts: 23586
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sahil Malkani:
What exactly is a Thread?I know it is used for multiple process execution!
But how would one define it?How does it really help in Simultaneous execution of code?
I just want to understand the basics!



You can start here with the tutorial from the Sun website.

Henry
 
author
Bartender
Posts: 4096
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should study general threads before concerning yourself with java threads.

I recommend the section on threading "Operating System Concepts" (an excellent reference book) available on amazon at:

http://www.amazon.com/gp/product/0471694665/102-5086074-6714526?v=glance&n=283155&n=507846&s=books&v=glance


To briefly answer your question, multi-threaded applications have advantages over single threading since:

- Can be adapted to systems with more than one processor easily, whereas truly single threaded applications running on a multiple-processor machine/system will only use one processor at a time.

- Its difficult for a thread to use 100% of the CPU during its entire life cycle. For example, anytime data needs to be loaded from disk (even RAM), the thread will pause and not use any CPU time while reading the data. This leads to a lot of wasted time, so having other threads to keep the CPU busy is prefable.

The only time multi-threading does not work is if you are constantly using 100% CPU and the code is extremely interdependant, ie complex Mathmatics code where each equation depends on the previous work.
[ November 29, 2005: Message edited by: Scott Selikoff ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There are two types of multitasking:

process based multitasking and
thread based multitasking.

In process based multitasking, two processes run concurrently on an operating system. For example, we can think of a word processor and an excel sheet running at the same time in parallel. These are two different programs that do not share common memory space ( in other words, they have separate data and code ) but they are just running in parallel.

Thread based multitasking is at a finer level than this. Two threads share the same memory space, they can operate on same data and they are usually parts of the same program. They have different execution paths and hence can run concurrently making an efficient use of operating system.

I would suggest to read the Sun Tutorial on threads, its excellent to begin with. When you feel like you have sufficient knowledge of threads, try writing some code on your own, that would give you first-hand experience.

Sun tutorial on threads

This is updated to include concepts from a new release.

All the best.

Soudamini
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!