Skip to content
Advertisement

Tag: synchronization

Is replacing one java object reference with another considered thread safe, or are there potential synchronicity issues I’m overlooking?

I’m rolling my own simple caching solution to improve the UX of a lengthy lookup. The basic outline is that I have a class handling all accountId lookups, and another class called AccountListCache with two variables: a timestamp indicating when it was created, and a List object containing a whole bunch of accountId objects. When the lookup is invoked, that

Do I need synchronize method Scheduled method?

I have a Spring schedulled tasks which calls the same private method. Do I need to sync this method? Will I have the problem if shedulled tasks runned in the same time? Or will be better to extract it to the prototype component or separate schedulled classes or something else? Answer The default ThreadPoolTaskScheduler used by the @Scheduled annotation is,

Multiple thread failed to execute the nonsynchronized code in java

If Thread1 get the lock and start executing the synchronized block, During the same time,Thread2 is free to execute the non-synchronized part of the code which is IntStream.range(0, 5).forEach(x -> System.out.println(“thread Unsafe Zone,”+name)). Unexpectedly,below is what actually happening while i run code. Explaintation- Suppose,thread1(or thread2) get the lock and execute the synchronized block and then thread2( or thread1) get the

Advertisement