synchronized Questions

21

Solved

I have a webapp that I am in the middle of doing some load/performance testing on, particularily on a feature where we expect a few hundred users to be accessing the same page and hitting refresh a...

18

Solved

I have some questions regarding the usage and significance of the synchronized keyword. What is the significance of the synchronized keyword? When should methods be synchronized? What does it me...
Flatulent asked 6/7, 2009 at 6:47

23

Solved

Whenever a question pops up on SO about Java synchronization, some people are very eager to point out that synchronized(this) should be avoided. Instead, they claim, a lock on a private reference i...
Character asked 14/1, 2009 at 10:37

6

Solved

Using the synchronized keyword method, using the javap command to view the bytecode, it is found that monitor is used, and if it is possible to call the monitor when the synchronized is implemented...
Pontifical asked 2/4, 2018 at 11:43

7

Solved

What does it mean when we say an ArrayList is not synchronized? Does it mean that if we declare an ArrayList in object scope, multiple threads accessing the objects have the opportunity to modify...
Sobersided asked 2/8, 2011 at 10:20

9

Solved

I'm looking for a way to synchronize a method based on the parameter it receives, something like this: public synchronized void doSomething(name){ //some code } I want the method doSomething to ...
Rockrose asked 16/9, 2012 at 20:20

6

Solved

Why exception execute when I removed some items in RecyclerView by using loop ? I used Collentions.synchronizedMap in adapter and 'deleteItem method' use synchronized too (the method in fragment). ...

4

Solved

Is there any way to block a critical area like with Java synchronized in Django?
Kaffiyeh asked 28/3, 2010 at 23:5

11

Solved

In Java, the idiomatic way to declare critical sections in the code is the following: private void doSomething() { // thread-safe code synchronized(this) { // thread-unsafe code } // thread-s...
Maffick asked 6/1, 2009 at 11:31

6

Solved

In the project I am coding, I need to return a thread safe and immutable view from a function. However, I am unsure of this. Since synchronizedList and unmodifiableList just return views of a list,...
Costumer asked 12/7, 2011 at 1:45

4

Solved

Let's say I have a java class with a method like this (just an example) @Transactional public synchronized void onRequest(Request request) { if (request.shouldAddBook()) { if (database.getByNam...
Lamaism asked 20/1, 2017 at 16:9

5

Solved

how can I provide synchronization upon method parameter values? All method calls using the 'same' parameter value A should be synchronized. A method call with a different parameter value e.g. B ca...
Macias asked 9/7, 2018 at 8:48

1

Solved

I have the following class: class SdkWrapper(private val sdk: Sdk) { private var inited = false suspend fun doSomething() = withContext(Dispatchers.IO) { if (inited.not()) init() useSdk() } ...
Fleming asked 9/10, 2020 at 9:9

2

You might think that this question is duplicate of this one but no answers of that question helps me for understanding synchronized method in android. I searched a lot on google for understanding s...
Heather asked 10/10, 2018 at 10:54

2

Solved

I'm trying to implement a simple read/write lock for a resource accessed concurrently by multiple threads. The workers randomly try reading or writing to a shared object. When a read lock is set, w...
Coucal asked 19/3, 2018 at 21:32

4

Solved

What does this java code mean? Will it gain lock on all objects of MyClass? synchronized(MyClass.class) { //is all objects of MyClass are thread-safe now ?? } And how the above code differs fro...
Amyloid asked 13/1, 2010 at 11:33

2

Solved

Recently I was reading the page The JSR-133 Cookbook for Compiler Writers by Doug Lea regarding JSR 133: JavaTM Memory Model and Thread Specification Revision. There I read this line: Memory barri...
Shocking asked 12/7, 2020 at 2:35

1

suppose we use double-check lock to implement singleton pattern: private static Singleton instance; private static Object lock = new Object(); public static Singleton getInstance() { if(inst...
Presentation asked 6/12, 2019 at 6:33

2

Solved

wondered if anyone could assist, I'm trying to understand the correct way to access a collection in Kotlin with two threads. The code below simulates a problem I'm having in a live system. One thr...
Electrolyse asked 9/2, 2020 at 14:33

5

Solved

During my interview, interviewer started his question with singleton pattern. I wrote below. Then, he asked Shouldn't we check for Nullity inside getInstance method? I replied with, It is NOT nece...

1

Solved

I m learning about java optional wrapper, to do so I m reading the following tutorial however I have a simple question that is not answered in the article: in item 25: Avoid Using Identity-Sensiti...
Barker asked 10/7, 2019 at 11:31

2

Solved

For a project I need to have a unique ID generator. So I thought about a Singleton with synchronized methods. Since a Singleton following the traditional Singleton pattern (private static instanc...
Mooneyham asked 9/11, 2014 at 19:1

12

If I synchronized two methods on the same class, can they run simultaneously on the same object? For example: class A { public synchronized void methodA() { //method A } public synchronized vo...
Calamint asked 15/3, 2013 at 17:35

11

Solved

If I have 2 synchronized methods in the same class, but each accessing different variables, can 2 threads access those 2 methods at the same time? Does the lock occur on the object, or does it get ...
Barretter asked 15/6, 2010 at 17:38

2

Solved

In Java 8, I can easily write: interface Interface1 { default void method1() { synchronized (this) { // Something } } static void method2() { synchronized (Interface1.class) { // Somethi...
Viridissa asked 4/5, 2014 at 7:6

© 2022 - 2024 — McMap. All rights reserved.