Question: 1/ What are the ways you can make an instance of your class be able to start a thread? In other words, what can you
1/ What are the ways you can make an instance of your class be able to start a thread? In other words, what can you add to your class definition to mark it as being capable to start a thread?
Multiple answers
- Just implement run() method without changing the class header
- Implement Synchronized interface
- Extend Thread class
- Implement Thread interface
- Extend MainThread class
- Implement Runnable interface
2/ What are some of the ways to achieve object locks by threads in Java?
multiple answers
- Static synchronization
- Concurrent blocks
- Synchronized method
- Synchronized block
- Adding transient keyword
- Changing thread priorities for each thread to ensure they are scheduled for execution sequentially
- Efficient thread communication
- Concurrent methods
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
