Introduction to Java threads

This tutorial explores the basics of threads — what they are, why they are useful, and how to get started writing simple programs that use them. We will also explore the basic building blocks of more sophisticated threading applications — how to exchange data between threads, how to control threads, and how threads can communicate with each other.

What are threads?
Nearly every operating system supports the concept of processes — independently running programs that are isolated from each other to some degree. Threading is a facility to allow multiple activities to coexist within a single process. Most modern operating systems support threads, and the concept of threads has been around in various forms for many years. Java is the first mainstream programming language to explicitly include threading within the language itself, rather than treating threading as a facility of the underlying operating system.

Threads are sometimes referred to as lightweight processes. Like processes, threads are independent, concurrent paths of execution through a program, and each thread has its own stack, its own program counter, and its own local variables. However, threads within a process are less insulated from each other than separate processes are. They share memory, file handles, and other per-process state.

A process can support multiple threads, which appear to execute simultaneously and asynchronously to each other. Multiple threads within a process share the same memory address space, which means they have access to the same variables and objects, and they allocate objects from the same heap. While this makes it easy for threads to share information with each other, you must take care to ensure that they do not interfere with other threads in the same process

Get download pdf Introduction to Java threads

Related Tutorial

Tags: , , , , , , , , , , , , , , , , ,

Comments

Leave a Reply