If interrupting the thread is not an option, another is to place a “marker” or “command” object on the queue that would be recognized as such by MyObjHandler and break out of the loop.
More Related Contents:
- Why must wait() always be in synchronized block
- How to share data with two(2) SwingWorker class in Java
- ConcurrentModificationException despite using synchronized
- Volatile vs Static in Java
- How to make ThreadPoolExecutor’s submit() method block if it is saturated?
- When would you call java’s thread.run() instead of thread.start()?
- Convert from List to CompletableFuture
- Why there is no ConcurrentHashSet against ConcurrentHashMap
- How to get the ThreadPoolExecutor to increase threads to max before queueing?
- How do I call some blocking method with a timeout in Java?
- Java Executors: how can I set task priority?
- What are the main uses of yield(), and how does it differ from join() and interrupt()?
- Volatile variable in Java
- What is the difference between synchronized on lockObject and using this as the lock?
- When should I use a CompletionService over an ExecutorService?
- Are non-synchronised static methods thread safe if they don’t modify static class variables?
- When do I need to use AtomicBoolean in Java?
- Java ExecutorService: awaitTermination of all recursively created tasks
- Hashmap concurrency issue
- Which concurrent Queue implementation should I use in Java?
- Why should I use concurrent characteristic in parallel stream with collect?
- Java concurrency: is final field (initialized in constructor) thread-safe?
- Java: ExecutorService that blocks on submission after a certain queue size [duplicate]
- Jboss Java EE container and an ExecutorService
- Java: is there no AtomicFloat or AtomicDouble?
- How to pause/resume all threads in an ExecutorService in Java?
- Multithreading Socket communication Client/Server
- Not thread-safe Object publishing
- notifyAll() throws IllegalMonitorStateException
- Will a chain of method calls (CompletableFuture API) execute asynchronously if the first method in a chain is asynchronous?