Institute of Computer Science
  1. Courses
  2. 2017/18 spring
  3. Object-Oriented Programming (Narva College) (P2NC.01.083)
ET
Log in

Object-Oriented Programming (Narva College) 2017/18 spring

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links
Session 14

Thread concepts

One of the powerful features of Java is its built-in support for multithreading — the concurrent running of multiple tasks within a program. A program may consists of many tasks that can run concurrently. A thread is the flow of the task execution from its beginning to the end.

A thread provides the mechanism for running a task. With Java, we can launch multiple threads. These threads can be executed simultaneously in multiprocessor systems. In single-processor systems the multiple threads share CPU time, known as time sharing, and the operating system is responsible for scheduling and allocating resources to them.

Multithreading can make our program more responsive and interactive, as well as enhance performance. For example, a good word processor let us print or save a file while we are typing. In some cases, multithreaded programs run faster than single-threaded programs even on single-processor systems. Java provides exceptionally good support for creating and running threads and for locking resources to prevent conflicts.

We can create additional threads to run concurrent tasks in the program. In Java, each task is an instance of the Runnable interface, also called a runnable object. A thread is an object that facilitates the execution of the task.

Session 14
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment