Skip to main content

All Questions

0 votes
1 answer
70 views

Is there a visibility problem with this initialization method?

Visibility problem: When multiple threads call method handle(), is the variable redisTemplate the initialized value, or is it null in some cases? Example here: public class InnerStaticClassExample { ...
TiaJiang's user avatar
2 votes
0 answers
72 views

Why this example doesn't exhibit visibility problem in concurrent code

I tried to avoid all common pitfalls of writing a code demonstrating the visibility problem in concurrent access in multi-threaded code. But still, the tested variable always shows the updated value; ...
Espinosa's user avatar
  • 2,573
0 votes
1 answer
565 views

Spring, instance variable visibility in new thread started from @PostConstruct

Does spring garantee visibility of 'sleepInterval' and 'businessLogic' instance variables in case below? import org.springframework.beans.factory.annotation.Value; import org.springframework....
Yurii Bondarenko's user avatar
1 vote
3 answers
538 views

Java Array Element Visibility Between Several Threads

Creating the Array: Uses the thread provided on startup since we only create the array once. public static final Player[] PLAYERS = new Player[10]; Writing to Array: Uses several different ...
Wonderlus's user avatar
  • 331
1 vote
1 answer
417 views

Using final variables in anonymous threads

Is it safe to do something like for (int i = 0; i < 10; i++){ final int finalI = i; new Thread(() -> { // use finalI in the thread somehow }); } So the question I want to ...
katiex7's user avatar
  • 913
2 votes
1 answer
231 views

Is happens-before transitive when calling Thread.start()?

Let's say we have a class class Foo { int x; Foo() { x = 5; } } and some client code public static void main(String[] args) { Foo foo = new Foo(); new Thread(() -> { ...
katiex7's user avatar
  • 913
4 votes
2 answers
218 views

Why is this never throwing an AssertionError even after running it for so long?

Here is the original code //@author Brian Goetz and Tim Peierls @ThreadSafe public class SafePoint { @GuardedBy("this") private int x, y; private SafePoint(int[] a) { this(a[0], a[1])...
katiex7's user avatar
  • 913
0 votes
0 answers
40 views

Visibility of final fields not set in constructor [duplicate]

I've seen a class do something like this class Foo { private final Set<Bar> set = Collections.synchronizedSet(new HashSet<>)); public void add(Bar b) { set.add(b); } ...
katiex7's user avatar
  • 913
4 votes
1 answer
174 views

Will this AssertionError never be thrown in this case?

First off the code, from JCIP listing http://jcip.net/listings/StuffIntoPublic.java and http://jcip.net/listings/Holder.java public class SafePublication { public static void main(String[] args) ...
katiex7's user avatar
  • 913
1 vote
1 answer
42 views

Does improperly constructed object only affect visibility for the thread it publishes inside of tbe constructor?

When http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#finalRight says The values for an object's final fields are set in its constructor. Assuming the object is constructed "correctly"...
katiex7's user avatar
  • 913
2 votes
2 answers
89 views

Are objects that have no state always visible when published?

Say I have a class public class Foo { public void printHi() { System.out.print("Hi"); } } and in some client code I do something like public static void main() { Foo foo = new ...
katiex7's user avatar
  • 913
2 votes
1 answer
696 views

Is everything that happened before thread.start visible to the thread that is spawned calling start?

Now there are great answers to this already on stackoverflow but they don't give me the definite answer I want. Say you have a method Dosomething(); doAnother(); int x = 5; Runnable r = new ...
katiex7's user avatar
  • 913
0 votes
0 answers
43 views

Is Concurrency In practice listing 5.15 broken? [duplicate]

In JCIP, listing 5.15, Goetz demonstrates a class using CyclicBarrier, but what intrigued me was that inside of the constructor of the class that uses this barrier, he lets the this reference escape ...
user8829487's user avatar
0 votes
2 answers
162 views

Does static provide additional guaranties in JMM context?

I am reading about java singleton and I've met strange things. I will refer to following artice as example(you can easy find more) Author provides the following singleton: public class ASingleton { ...
gstackoverflow's user avatar
0 votes
1 answer
73 views

What is the deal with modifying the volatile boolean field of an object, while holding the specific monitor, when lazy locking?

I implemented a lazy locked list, that supports the following methods: boolean add(T item), boolean remove(T item), boolean contains(T item). For example the add method: @Override public boolean ...
Greg's user avatar
  • 49

15 30 50 per page