Questions tagged [synchronized]
A block or method is said to be 'synchronized' if entry to it is controlled by the Java `synchronized` keyword. This causes access to it to be restricted to a single thread at a time: when concurrent accesses occur, they are sequentialized in an unspecified order.
synchronized
1,885
questions
0
votes
2
answers
80
views
Can we avoid the use of Volatile in Singleton Pattern by making the getInstance() method synchronized in Java?
In most places, this is the implementation followed for Singleton Design Pattern.
It makes use of the keyword volatile to prevent the issue of partial object creation (establishes happens-before ...
-4
votes
1
answer
54
views
LeetCode 1116 Java Concurrency Issue, will waiting thread revisit code before? [closed]
Here is my code for the problem which works fine, however, when I change the while statement right under synchronized statement, it seems any thread that get the lock after notifyall() just continue ...
0
votes
1
answer
69
views
How to solve the resource temporarily unavailable problem when using YCSB to generate multiple clients to access rocksdb?
When testing the performance of Rocksdb with multiple column families using YCSB, I used four clients to load workloads on Rocksdb and wrote a script to execute four commands in parallel. The content ...
1
vote
1
answer
43
views
Unexpect Behavior with Multiple Java Threads and TreeMap.put()
When running the following code:
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
public final class ThreadTest {
int N = 4;
Map<Integer, Proxy> proxy = ...
-2
votes
1
answer
33
views
Race condition in ThreadPoolExecutor [duplicate]
What code must to do:
execute Bot#run synchronous.
What need to fix:
sharing resource (Bot.responseData or.. more) between other bots and threads.
Bot.run() execution stages:
http request -> ...
2
votes
3
answers
86
views
Why would I ever create a separate mutex/lock object?
I am modifying some concurrent code at work and recently read through Java's docs on Intrinsic Locks and Synchronization.
Given that every object has an intrinsic lock, why would I ever create a ...
0
votes
1
answer
10
views
How to verify the synchronization results of tsfle in Apache IoTDB when using `pipe`?
When I synchronize tsfile from Apache IoTDB server A to server B through pipe, how to verify the synchronization results, and how to know whether the synchronization is successful? What result ...
0
votes
0
answers
14
views
HTML Helper Has A Different Value Than Model
I'm Trying to figure something out. I have a form in a cshtml file that has some elements on it:
<div id="RemitContainer">
@{
Html.BeginForm("SaveClientRemit", "...
0
votes
1
answer
45
views
Multi-threaded Java application is behaving unexpectedly. Can someone point out the problem?
I have a simple class which does not behave as expected. I'd like to point out that this class is the whole application. I'll show the code, the output, and then ask my question.
import java.awt.Image;...
-1
votes
1
answer
59
views
Thread runs infinitely because `synchronized` does sync access to a field and 4 methods in a concurrency test with two threads
Things to Note:
I use JetBrain IntelliJ IDEA Community Edition.
My code relies on 3 short classes. Easy to read.
The original code runs as it is and produces the appropriate result. See image at ...
1
vote
1
answer
68
views
Why is the Synchronized Block invalidated?
As known that List is not thread-safe, I add synchronized to the code in 2 methods shown below.
1.
public class TestSyn
{
public static void main( String[] args ) throws InterruptedException
{
...
-2
votes
1
answer
108
views
Best way to call common methods from a Callable class?
I use java classes of type Callable (up to 200 in parallel), which call a method of a tool class (centralizing common methods), and I notice that if this method is not 'synchronized', I get errors.
I'...
-2
votes
2
answers
63
views
What is causing racing condition in the buffered class
I'm trying to create a generic class to make some synchronized buffered writing operation.
I'm trying to minimize lock time, so i used a non final lock object that im my mind would be enough to keep ...
1
vote
2
answers
54
views
Synchronized keyword not working as expected when monitor object is shared between multiple threads
I am practicing java multi threading and concurrency. So I am currently working on wait() and notify() functionality. I have created below code
public class WaitAndNotifyTest {
public static ...
0
votes
1
answer
178
views
How CPU switches the execution from one thread to another to access a lock resource in Java?
I'm learning about multi-threading in Java and I have a short question.
I have a synchronized block or method and 2 (or more) threads. And I have only one CPU with only one core, so the 2 threads will ...