Java Concurrency

Introduction

  • In older version of Java, when a new Java thread is started, the call is delegated to the OS which creates a new OS thread with a separate JVM instance.

  • In more recent versions of Java, there is an increasing trend towards runtime-managed concurrency, the concept where the developer is discouraged from explicitly managing threads. Instead, the developer should take a “fire and forget” approach, where the program specifics of what needs to be done is specified, leaving the low-level details of how this is done to the runtime.

Visibility and Mutability

  • All Java application threads in a process have their own call stacks and local variables, but share a single heap. This makes it easy to share objects between threads with pass by reference.

  • Because Java objects are mutable (object instance’s fields can be changed) and the shared single heap, it creates complexities with concurrent Java applications.