Threads vs. Processes

Beginner Algorithms and Data Structures English
Also available: Deutsch
Created by Best · 16.08.2026 at 09:13 UTC

A process has its own address space. Threads of the same process share the heap but have their own stacks. In Java, threads are started through the Thread or Executor services.

Concurrency enables parallelism on multi-core systems but requires synchronization.

Where used

Web worker pools, parallel requests, background jobs. Processes isolate address spaces (security, crash); threads share the heap and require synchronization.

Depth

Processes have separate virtual address spaces and are more strongly isolated from each other by the operating system. Communication requires explicit mechanisms such as pipes, sockets, or shared memory. A failure in one process does not easily corrupt the data of another.

Threads of a process see the same objects and resources but have their own call stacks and register states. The exchange is therefore efficient, but synchronization obligations arise. The choice depends on isolation, communication costs, and the nature of the work.

Difficulty levels

  1. Distinguishing between separate and shared states.
  2. Weighing communication and fault isolation costs.
  3. Assigning a CPU- or I/O-intensive task to a suitable structure.

Pitfalls

Threads do not necessarily run simultaneously but can only be time-multiplexed. Multiple processes also do not guarantee acceleration if communication or resource scarcity dominates.

University approvals: 0
Tasks
Question 1

What do threads of a Java process typically share?

Question 2

Which property favors separate processes for error-prone components?

Question 3

Return the ID of the currently running thread.

Hint

The current thread is provided by Thread.currentThread(). Its ID is available as a long through the appropriate instance method.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Algorithms and Data Structures
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Best
Best
BestBuddy