Header javaperspective.com
JavaPerspective.com  >   Intermediate Tutorials  >   2. Concurrency

2. Concurrency
Last updated: 25 January 2013.

When you run a Java program, the execution takes place in a single process. Roughly speaking, a process contains the program's code and holds data including the available memory of the program and information about the program's owner and the program's permissions.

In the Java language, concurrency is the ability for a process to create and run multiple threads of execution simultaneously. A thread of execution is nothing more than a lightweight process that heavily depends on the resources of the process that created it. In particular, a thread shares the process memory. It also shares the open files of the process. Consequently, when several threads access a resource concurrently, it can lead to concurrent access problems or unwanted results. For example, if several threads are writing lines of text that end with a carriage return in the same text file, two lines of text written by two different threads may overlap. The Java language provides concurrency support to address such problems.

On computers that have a single processor, multithreading (running multiple threads) is achieved by sharing the processor between the threads. Basically, each thread is executed during a short time slice. The processor switches between the threads so rapidly that it seems to the user that the threads are running in parallel. On multi-processor computers, each processor can run a single thread, allowing multiple threads to run simultaneously without time slicing mechanisms.

The next tutorial will show you how to create and run threads.



You are here :  JavaPerspective.com  >   Intermediate Tutorials  >   2. Concurrency
Next tutorial :  JavaPerspective.com  >   Intermediate Tutorials  >   2. Concurrency  >   2.1. Threads

Copyright © 2013. JavaPerspective.com. All rights reserved.  ( Terms | Contact | About ) 
Java is a trademark of Oracle Corporation
Image 1 Image 2 Image 3 Image 4 Image 5 Image 6 Image 7