Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads  RSS feed

 
Sahil Malkani
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!
 
Henry Wong
author
Sheriff
Posts: 23275
125
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
 
Scott Selikoff
author
Bartender
Posts: 4087
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 ]
 
soudamini.s shirkhedkar
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!