Junior — Middle
Can you name the main key terminologies used when working with multithreading in Java?
sobes.tech AI
Answer from AI
Key concepts when working with multithreading in Java:
- Thread — a separate thread of execution within a program.
- Runnable — an interface that describes a task to be executed in a thread.
- Synchronization — a mechanism to prevent concurrent access to shared resources.
- Monitor — an object used to control access to a critical section.
- volatile — a variable modifier that guarantees visibility of changes across threads.
- Deadlock — a situation where two or more threads wait forever for resources held by each other.
- ExecutorService — a high-level API for managing thread pools.
Example of creating and starting a thread:
Thread thread = new Thread(() -> {
System.out.println("Thread started");
});
thread.start();