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.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
22 views

logstash used with ms sql server to ingest data to elastic seach server [closed]

What is the most efficient solution for synchronizing data between Elasticsearch and SQL Server databases with a large number of tables. and how can this real time. My stack is python, django, kibana ...
Alberuni Beruni's user avatar
0 votes
1 answer
68 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 ...
elvis's user avatar
  • 838
1 vote
2 answers
84 views

Is it mandatory to declare a variable volatile when I have a synchronized block to increment an int in Java?

I'm learning about concurrency in Java and I'm watching a YouTube video. It is an explanation about increment operation in a multi-threading environment. The solution for that could be a volatile ...
elvis's user avatar
  • 838
0 votes
0 answers
22 views

PowerShell PictureBox Object in a New Runspace - Not Showing

I have a button click event handler that runs commands. I wanted to add a spinning wheel GIF for the user experience. I added a picturebox object with the GIF as the image. If I change the visibility ...
AOEMilad's user avatar
0 votes
1 answer
67 views

What might thread-safety entail in a typical storage environment? [closed]

I'm learning multi-threading in java. I wrote a simple generic storage class that always stores objects in ascending order. I now wanted to make it thread-safe. One way (and probably the easiest way) ...
kesarling He-Him's user avatar
0 votes
1 answer
77 views

Are object parameters of synchronized block guranteed visibilty Synchronized Java

I cannot find an answer for the following case: public class Example { int a=0; public synchronized void method(Object x){ a++; x.value=x.value+1; } } I know that ...
Mohammad Karmi's user avatar
0 votes
0 answers
7 views

How to synchronize tsfiles with mod files in Apache IoTDB?

When I am doing data synchronization in Apache IoTDB, all tsfiles with mod files cannot be synchronized. Why IoTDB produced these mod files, and how should I deal with this problem?
Li Yu Heng's user avatar
0 votes
1 answer
102 views

Java memory visibility outside the synchronized lock

Does the synchronized lock guarantee the following code always print 'END'? public class Visibility { private static int i = 0; public static void main(String[] args) throws ...
Anonemous's user avatar
  • 309
2 votes
2 answers
62 views

Limit concurrent Threads in Spring Web Method

I have a spring Web MVC application which has a Web Method in SOAP called calculateWebMethod. Because of the number of concurrent requests the server was overloading and my team decided to make the ...
Cesar Lopes's user avatar
-3 votes
2 answers
61 views

Thread Safety in operations involving ConcurrentHashMap in Java

Context: I'm creating a new Item, caching it and returning it, however, its name must be unique. We're talking about multithreaded env. My questions are in the comments. class ItemOperations { ...
HyperVol's user avatar
  • 150
1 vote
3 answers
73 views

Could 2 threads execute the same synchronized instance method if the monitor object is different in Java?

I'm new to Java concurrency and I know that an instance method synchronized means that only one thread can execute that method at a time. But does this thing depends on the monitor object or not? ...
elvis's user avatar
  • 838
0 votes
1 answer
96 views

Is this implementation correct?

I was wondering if this implementation is correct. The scenario is: one overseer unknown number of workers (0-n) overseer only needs to convey resume work or production has stopped signals to the ...
JayC667's user avatar
  • 2,504
0 votes
1 answer
54 views

java synchronized how can i understand it

import java.util.ArrayList; import java.util.List; public class unsafeList { public static void main(String[] args) throws InterruptedException { List<String> list = new ArrayList&...
1earing's user avatar
0 votes
1 answer
57 views

Visibility of HashMap elements in synchronized block

I have researched many times to find out an answer for my question. In Spring, we have this class https://github.com/spring-projects/spring-framework/blob/b595dc1dfad9db534ca7b9e8f46bb9926b88ab5a/...
Роман Григорьев's user avatar
0 votes
2 answers
41 views

How do I conditionally lock a method based on its parameter in Java?

I have the following method which runs 'SubJobs' for a given JobModel parameter: public void runSubJobs(JobModel jobModel) { LOGGER.log("Start executing SubJobs for " + jobModel.getId())...
Felix Schildmann's user avatar
-2 votes
1 answer
43 views

Do we need to use a synchronized block for Room database [closed]

I have some code that I would like to use something like a threadpool because I am making multiple transactions at once. I used to use a SQLite database with a synchronized block. I figure that Room ...
user1743524's user avatar
0 votes
2 answers
65 views

Java singleton lazy initialization. Volatile vs synchronized method

Why do we need to add volatile to field to prevent invalid data retrieval? Can't we do the same thing by adding synchronized to method declaration instead of to a block of code? public class ...
kaka's user avatar
  • 625
0 votes
1 answer
103 views

Locking with synchronized block vs Explicit Locking

I implemented a barrier in java using synchronized block and got IllegalMonitorStateException. On replacing that synchronized block with explicit locking with lock.lock() and lock.unlock() in await ...
gaurav's user avatar
  • 3
0 votes
0 answers
32 views

Synchronising @Transactional method

I have a synchronised method with an annotation @Transactional, like below: @Transactional public synchronized void myMethod() { ... } The goal is to make sure no two threads calling this method (i.e....
user1589188's user avatar
  • 5,408
-1 votes
1 answer
68 views

Race condition with synchronized() blocks

package server.Bank; import server.Bank.Exceptions.*; import java.util.ArrayList; public class Bank { private final ArrayList<Account> accounts;//lista di account private final ...
esthy05's user avatar
0 votes
1 answer
49 views

Why does reinitializing an object used in thread synchronization not result in a deadlock?

Can someone please explain why the following code will not result in a deadlock? public class Example { private static Object object; public static synchronized void init() { if (object == ...
BJ Dela Cruz's user avatar
  • 5,234
0 votes
1 answer
74 views

Synchronized issue

I am trying to block the concurrent access to a method , and i didn t succeeded whatever i tried.I tried to sinchronize the method by class (by using synchronized(this) or synchronized at method ...
Uta Alexandru's user avatar
1 vote
2 answers
87 views

Java Synchronisation Atomicity

My single-threaded application writes to two memory mapped byte buffers (backed by two memory mapped files) Another Java application is reading from these files. I would like to make writing to both ...
Abidi's user avatar
  • 7,876
0 votes
1 answer
53 views

Parallelize execution on 2D Array - lock single field / cells of array

Iam working on the parallelization of the calculation of a 2D-Array. To be more precise, iam trying to parallize the simulation of a predator-prey szenario. Therefore, i am using a 2D-Array, in which ...
Adrian Weber's user avatar
0 votes
1 answer
52 views

While the thread is working, the ordinary variables are flushed to main memory

As I understand it, the memory.a should be in worker cache memory when the thread is not stopped. example: public class SynchronizedMemory { // non-visible private int a = 0; public ...
Ysngzhou Liao's user avatar
0 votes
0 answers
112 views

Android synchronized block causing ANR issue

Following is my code @NonNull private T readLocalResource() { synchronized (this) { if (data == null) { String resourceAsString = sharedPreferences.getString(key, null); ...
amodkanthe's user avatar
  • 4,387
0 votes
1 answer
68 views

Why are all my threads using the same lock?

I recently came across this code snippet class Counter2 implements Runnable{ private int value = 0; private Integer lock = 0; public void increment(){ try { ...
H-Bar's user avatar
  • 61
1 vote
1 answer
169 views

Kotlin synchronized returning to outer function causes issues

Consider the following code in Kotlin: private val mLock = "lock" suspend fun doJob(): String { synchronized(mLock) { if (someBoolean1) { return "A" } if (...
Damia Fuentes's user avatar
0 votes
2 answers
104 views

Calling toArray() on a synchronized array list a thread safe operation?

I am creating and using a synchronized array list which is being accessed/modified by multiple threads. In a certain operation I want to remove all elements of this synchronized list and process them. ...
CS1999's user avatar
  • 323
-1 votes
1 answer
92 views

Print numbers from one to ten

I have to print the numbers between one to ten , with ten threads and they got to be consecutive numbers. I mean Thread0 - 10 print 1,1,1,1,1,1,1,1,1,1 then Thread 0-10 print 2,2,2,2,2,2,2,2,,2,2 ...
Slavi Donchev's user avatar
0 votes
1 answer
56 views

Why does the following code cause unstable deadlock?

enter image description here I want to verify the synchronized keyword!!But the results didn't agree with what I predicted!!I don't understand why deadlocks happen private final ReentrantLock lock = ...
沃司机i's user avatar
0 votes
2 answers
94 views

Synchronized keyword in not giving expected result in java

Not getting expected output by using the synchronized keyword in java I tried to implement thread synchronization using synchronized keyword in java but am not getting the expected output. The final ...
Rohit Godara's user avatar
0 votes
2 answers
71 views

There is no problem when I run the following code with jdk1.8, but it will block when I run it with jdk11

public class Test { public static int num = 0; public static void main(String[] args) { new Thread(Test::printer, "t0").start(); new Thread(Test::printer, "t1&...
Mr.Chen's user avatar
1 vote
2 answers
53 views

Can we achieve visibility and atomicity using Volatile and Synchronized together?

I am just trying to understand... Will I achieve the same result using the below two approaches? I mostly see the first approach only. Is there anything wrong with the second approach? We can use ...
itspr's user avatar
  • 273
1 vote
1 answer
256 views

Can I use @Synchronized annotation in Kotlin Multiplatform commonMain code?

Can @Synchronized annotation be used in common code (commonMain) code of Kotlin Multiplatform? The library only targets JVM and JS. Will it have any impact on a Kotlin/JS application that calls the ...
nightlytrails's user avatar
0 votes
2 answers
138 views

Example where Java lock works but synchronisation doesn't

I have been looking into scenarios where using Lock, ReentrantLock fits perfectly fine, but that scenario would be unachievable by using usual synchronisation. The official javadocs says: There are ...
Deca's user avatar
  • 1,165
0 votes
0 answers
28 views

Synchronized list in java Collections Framework

In the below Java code, I am trying to create a synchronized List from normal ArrayList and then performing the multithreading operation but still it gives ConcurrentModificationException. Can someone ...
Nitesh Agrawal's user avatar
0 votes
1 answer
34 views

Synchronized getter and synchronized thread run method in java

The followiing code uses threads to calculate the max value in a subarry, and then calculates the max value out of the max values the threads returned. I have a bug that the main thread doesn't wait ...
GuyO's user avatar
  • 51
0 votes
1 answer
43 views

Is there different scala lock synchronized usage?

I learned that in scala we can use synchronized like next synchronized(Object) function with synchronized However i found some codes Object synchronized{ .... } lock = new Object lock synchronized{ ...
anatmy's user avatar
  • 11
0 votes
1 answer
93 views

Java locking simple multi threaded queue class to avoid starvation

I'm currently reviewing concurrency and wanted to double check my understanding. Let's say I have a simple queue class that I want to use multiple threads to take jobs off of the queue and run. class ...
Kevin's user avatar
  • 3,239
0 votes
1 answer
147 views

Failed for SynchronizedCollection while serializing an array list

Here is the error stack, java.util.ConcurrentModificationException at java.util.ArrayList.writeObject(ArrayList.java:766) at java.lang.reflect.Method.invoke(Native Method) at java.io....
Shawn Wong's user avatar
1 vote
1 answer
83 views

How does Object.notify() work with Object.wait()?

I am trying to track a resource which behaves in an asymmetric manner. That is, it responds immediately to a start() request, but finishes processing a cancel() request at a significant delay. For ...
WebViewer's user avatar
  • 791
1 vote
1 answer
128 views

How to make a thread skip to the next line of code when callling a synchronized method that's currently blocked?

Scenario Multiple threads add objects to an ArrayList list, which is an attribute of a ListHolder object listHolder, which is shared by all the threads. The threads call ListHolder.addObject() to add ...
Andikan Otung's user avatar
0 votes
1 answer
45 views

Why synchronized shows BLOCKED state and Locks and semaphores shows WAITING state of the Threads

When threads are waiting to access the critical section using synchronized block why the threads states show as BLOCKED and when the threads are waiting to access the critical section using Lock or ...
Adarsh Verma's user avatar
0 votes
1 answer
299 views

How to synchronise shared tooltip and crosshair in highcharts?

I have a couple of charts, some with a single series, others with multiple series. I show shared tooltips for charts with multiple series. I show a vertical crosshair on each chart. Now I would like ...
Pauli's user avatar
  • 31
0 votes
0 answers
187 views

Execute Synchronous / Blocking API calls in react

I'm implementing a login action which I would like to run synchronously. My handler Function ` const handleSignIn = async () => { try { const user = await Auth.signIn(email, password); /...
0210vidit's user avatar
  • 109
0 votes
0 answers
29 views

Can't implement synchronization in class [duplicate]

In the course of training, as well as with the analysis of multithreading, I decided to try my hand at thread synchronization. In this regard, I made a small test, where the creation of threads occurs ...
Fobos1996's user avatar
0 votes
1 answer
51 views

How could I force the execution of a function in Node.js?

I'm making a website in which I could learn the flags from all around the world. The idea is before the front is loaded, my back choose a random int, and pick a flag at this id from my database, and ...
Lucas Martin's user avatar
0 votes
2 answers
68 views

How can I use synchronized block well?

I want to print "ping" "pong", which are in same class but different method, 5 times using synchronized block. The problem is that it stops after print ping pong once. How can I ...
Sungjoon Ha's user avatar
0 votes
0 answers
32 views

How can I get values dynamically from SQL Server to .NET Framework web project?

I am a newbie coder. I am building a website and need some help. I will try to explain what I need. I have a table named tbl_Orders in SQL Server And this is my ViewBag in the controller side of ....
Cooper's user avatar
  • 31

1
2 3 4 5
38