ConcurrencyHomepage  « Learn Java5 « Concurrency

In our sixth section on learning Java5 we look at multithreading and how to run parts of our program concurrently. We explain the terminology behind concurrency before looking in detail at running parts of a program concurrently by subclassing the Thread class and also by declaring a class that implements the Runnable interface. Running separate threads at the same time is great and we can certainly improve the performance of our programs using multithreading. But what happens when concurrent threads need to access and update some shared resource? Java deals with this problem with synchronization and we investigate how we can control access to our code by synchronising at the method or block level. After this we investigate thread priorities and how we can have the priority set automatically by the invoking thread or assign thread priorities ourselves using methods of the Thread class. We finish our look at concurrency by looking at how threads can interact with each other when they are within a synchronized method or code block.


Thread Basics

In the first lesson of this section we look at multithreading and explain the terminology behind concurrency before looking in detail at running parts of a program concurrently using the Thread class and subclasses thereof.


The Runnable Interface

In the last lesson we saw how to run parts of a program concurrently by subclassing the Thread class. The second way of running parts of a program concurrently is by declaring a class that implements the Runnable interface and is the subject of this lesson


Synchronization

In Java every class has a lock and each instance of a class we instantiate also has it's own lock. In this lesson we look at synchronization and how we can control access to our code at the method or block level using these locks.


Thread Priorities

In this lesson we investigate thread priorities and how we can have the priority set automatically by the invoking thread or assign thread priorities ourselves using methods of the Thread class.


Thread Communication

The Object class comes with three methods that are for use within synchronized sections of code and as they belong to the Object class are available through inheritance to all objects we create. The methods in question are wait(), notify() and notifyAll() and allow threads to communicate to other threads that they are, entering a blocked state or leaving a blocked state, so they can cease or resume execution respectively and is the subject of this lesson.


go to home page Java5 Tutor Homepage go to top of page Top





All the Java5 Concurrency lessons are listed below. Click a link to go to that lesson.


Concurrency

Thread Basics

The Runnable Interface

Synchronization

Thread Priorities

Thread Communication