I am trying to achieve that thread2 should complete first, then thread1, For this O am using join() method. But if I uncomment the System.out.println() present in the try block of thread1 class. then code give null pointer exception. Why in try block I need to add line, it doesn’t make any sense that adding a line code start working.
Tag: concurrency
Concurrency – Two threads querying multiple databases from different servers and compare each record synchronously
I want to have two threads querying (JDBC) two tables (from different servers/databases but related) for an ordered output then compare them or apply some logic record by record. The table size can be …
Can a thread lose control after calling a method but before the first instruction of the method?
I need to record the exact order in which a method is called by various threads in Java. I’m supposed to use an object timeProvider which returns non-decreasing long integers. The solution I have come up with is: Of course it is a bottleneck because the only place I need to use synchronization is the first line. So I’m wondering
Custom hashCode implementation for ConcurrentSkipListMap doen’t work as expected
The idea is to allow ConcurrentSkipListMap to store only one ApprovalRequest which has unique customerId and its state is PENDING. I supplied overridden hashCode and equals implementations. Moreover, …
how to understand this interface Executor example in Java API docs [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question Can anyone help to explain this piece of code in details? I am learning java concurrent programming. When i was
Confusing reason for thread waking up when condition does not hold
I am currently reading Effective Java and I am on the concurrency chapter. While explaining reasons a thread might wake up when a condition doesn’t hold (condition of while loop in which a wait() call abides) there is one reason that is pretty confusing to me and I can’t seem to understand it. Another thread could have obtained the lock
ConcurrentModificationException when iterate through ImmutableMap.copyof()
Currently, I have a problem when I frequently iterating through a HashMap (1-time per second) I add new element to the map on the main thread and iterate the map on the other thread I return an ImmutableMap.copyOf() to iterate through it, and sometimes I add a new element to the map. But it throws me a ConcurrentModificationException My pseudo-code:
How does java IoC framework ensure thread safety?
Recently I have read a great tutorial of Java Memory Model. It says JVM only guarantees the visibility of final field if no synchronization used. Then it occurs to me that when we use some IoC frameworks, we usually use setter injection/field injection which are not protected by final semantics. For example, If it is possible for some thread to
What is a usecase for Java AtomicReference#getAndSet?
What is a usecase for Java AtomicReference#getAndSet? In other words, is it correct assumption, that if the only method from AtomicReference that I use in my code is AtomicReference#getAndSet, then I do not need AtomicReference at all, just a volatile variable would be enough? For example, if I have the next code: , isn’t it always doing exactly the same
ForkJoinFramwork, call compute() directly without explicit ForkJoinPool/ExecutorService
Q: What happens when the compute() method, in a class “X” that extends RecursiveAction/Task, is directly called? Without calling a ForkJoinPool explicitly like the following: Instead a function call like the following still produce a similar result: What happens when the fork()/invokeAll() method inside class X is called (explicit ExecutorService is absent)? My assumption would be, when an fork() or