Multithreading in Java
page 1 of 5
Published: 14 Aug 2007
This article examines the basic concepts of implementing multi-threading in Java.
by Debjani Mallick
Average Rating: 
Views (Total / Last 10 Days): 24112/ 17


Multithreading is a process that allows a multitasking operating system to work on different portions, i.e., threads of a single application smoothly. In other words, it can be described as a form of parallelism where multiple threads can run in a concurrent manner.

Java supports programming for multitasking environment where the CPU can perform different tasks simultaneously. The multitasking environment can execute in two ways.

·         Process based multitasking

·         Thread based multitasking

Process based multitasking – A process is a program which is currently acquiring the CPU time and, hence, it is the currently executing the program. The process based multitasking can execute two different processes simultaneously where the processes are running under different locations. For example, we can write some text using editor, at the same time some other software can play music.

Thread based multitasking – Thread is the smallest unit of dispatchable codes. In a thread based multitasking environment, one program can perform two different tasks. Therefore, we can say that two different tasks are executing. For example, we can print a word document at the same time we can do some typing.

The threading concept says that the different blocks of the same program can be executed concurrently. In Java, for implementing threading, there is a built-in class called Thread. There are various methods supported by Thread class.

·         setName() – It takes a string argument and assigns it as the name of the thread.

·         getName() – It returns a string which indicates the name of the thread though it does not take any argument.

·         sleep() – It accepts an argument of long integer type and it tells the thread to wait for certain milliseconds.

·         isAlive() – It determines whether a thread has completed its execution or not. It returns true if the thread is still executing.

·         join() – This function tells a thread to wait for completion of another thread.

·         start() – It invokes the threads or starts the thread.

·         run() – To run a thread, we need this. It contains the codes which are executed when a thread is running.

View Entire Article

User Comments

Title: good   
Name: sathyaraj
Date: 2008-07-01 4:52:18 AM
we learn more about multithreading .............
Title: Thread program not working   
Name: Thread program not working
Date: 2008-04-30 6:25:37 AM
Listing 1
Thread program not working
Title: Very Nice   
Name: Ajit
Date: 2007-08-20 3:20:09 AM
Keep Up
Title: Nice   
Name: Jonas
Date: 2007-08-15 10:48:08 AM
Its a good piece of writing
Title: Good   
Name: Rocky
Date: 2007-08-14 10:37:54 PM
Keep up the good work

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-07-23 1:41:14 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search