Skip to content
Advertisement

Tag: java-threads

Thread-safety of int field in Java

If class has field with int type (not Atomic Integer and without volatile keyword) and all access to this field happens under read/write locks – will this field thread-safe in this case? Or in some moment some thread can see not real value of this field but something from cache? Answer Get answer from @pveentjer in comments under question: It

Thread not awake when timed wait elapsed in java

I am study wait(long timeout) in java,and in the offcial document I found below description: Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened. Some other thread invokes the notifyAll method for this object. Some other thread interrupts thread T. The specified amount of real

Call to method with a thread inside implies a wait?

I have a method that writes a file and it can be a bit slow. So I did this to avoid blocking the rest of actions: However it still takes a while until things B are executed after things A and I was wondering if I should do this instead: Or, in other words, does calling a method with a

isInterrupted() still returns “false” even after the Thread.State is “TERMINATED” in Java’s Thread – why?

When thread gets terminated (Thread.State.TERMINATED) it is still not interrupted. Why? I found this, and I found this, but neither answers my question.I have tried this out on OpenJDK 11 and Oracle JDK 16 – no difference, same result. I have been working with Java for more than 10 years now, and multithreading tasks have always been clear to me;

Java: is it possible to create a garbage-collectable object that includes an internal heartbeat thread?

Quick question: Is is possible to create a class such as it contain an internal infinite thread (heartbeat) and its objects are automatically garbage collected? Long question: I intend to create a class that includes an internal infinite background thread (such as a heartbeat). Although, the objects of this class shall not need an explicit destroy and shall be garbage-collected

Advertisement