synchronized Questions
1
Solved
I noticed a weird construct in ConcurrentHashMap's compute and computeIfAbsent methods:
Node<K,V> r = new ReservationNode<K,V>();
synchronized (r) {
//...
}
What is the point of syn...
Shed asked 21/10, 2014 at 8:28
5
Solved
I have a Bank class with a list of Account. The bank has a transfer() method to transfer a value from one account to another. The idea is to lock both the from and to accounts within a transfer.
T...
Thar asked 19/10, 2011 at 23:4
2
Solved
Do all non-retreival operations on a ConcurrentHashMap (put(), remove() etc.) need to be wrapped in a synchronized(this) block? I understand that all of these operations are thread-safe, so is ther...
Uhhuh asked 23/9, 2014 at 15:6
3
Solved
I created a small Java servlet for a simple purpose: Once it is called, it will do the following steps:
Read file foo.json from the local filesystem
Process the data from the file and do some cha...
Hammers asked 28/8, 2014 at 11:55
6
Solved
I have written one program where two threads are running that's why i have used synchronized keyword. My code is below-
public class TestThreadAnother {
public synchronized void decrement(){
try...
Emileemilee asked 9/7, 2014 at 6:0
5
Solved
I'm building a simple program to use in multi processes (Threads).
My question is more to understand - when I have to use a reserved word synchronized?
Do I need to use this word in any method ...
Stentorian asked 9/6, 2014 at 21:1
6
Solved
Say that I have a private variable and I have a setVariable() method for it which is synchronized, isn't it exactly the same as using volatile modifier?
Nightdress asked 22/5, 2011 at 16:2
2
Solved
I read this in an upvoted comment on StackOverflow:
But if you want to be safe, you can add simple synchronized(this) {}
at the end of you @PostConstruct [method]
[note that variables were NO...
Farver asked 28/5, 2014 at 8:43
3
Solved
Suppose I have the following code in Java
a = 5;
synchronized(lock){
b = 5;
}
c = 5;
Does synchronized prevent reordering? There is no dependency between a, b and c. Would assignment to a first...
Walden asked 24/4, 2014 at 16:0
1
Solved
I am overriding a method from superclass, however I want this method to be synchronized.
Is it allowed? What could be the alternative?
Tiresome asked 21/3, 2014 at 7:52
2
Solved
I know what @synchronized() does, but...
sometimes we have:
1- @synchronized(self)
2- @synchronized([MyClass class])
3- @synchrinized(myObj)
What is the difference, and what is the parameter ...
Venepuncture asked 18/3, 2014 at 11:58
1
Solved
In a method like this, which do synchronize (i.e. self or thing)?
- (BOOL)deleteThing:(MSThing *)thing error:(NSError **)error
{
@synchronized(self) {
if (!thing) {
return YES;
}
NSString *f...
Meaty asked 17/3, 2014 at 18:5
4
Solved
Today I saw this utility class for AtomicEnum but I wonder if it is possible to have an atomic enum why it is not included in Java standard libraries? In fact I have so much doubt if it can be real...
Lockup asked 19/12, 2013 at 15:51
2
Solved
In Objective C I'm using a NSMutableArray instance from various thread and I'm using @synchronized to make it thread safe. currently all my acces to this array are protected with a @synchronized bl...
Bitterling asked 13/6, 2013 at 15:44
4
Solved
What happens when two threads call the same static method at the same time? For example:
public static String someMethod(){
//some logic, can take about 1 second to process
return new String(r...
Succotash asked 18/2, 2014 at 20:39
2
Solved
When an object needs to be synchronized, the IDE complains if it's not set non-final (because its reference isn't persistent):
private static Object myTable;
....
synchronized(myTable){ //IDE com...
Fuselage asked 30/1, 2014 at 14:4
3
Solved
I recently discovered that using synchronized won't prevent any dead locks.
E.g. within this code:
ArrayList <Job> task;
...
public void do(Job job){
synchronized(tasks){
tasks.add(job);...
Disendow asked 29/1, 2014 at 18:19
3
Solved
I'm having a little difficulty understanding volatile variables in Java.
I have a parameterized class that contains a volatile variable like so:
public class MyClass<T> {
private volatil...
Cindicindie asked 6/6, 2013 at 15:9
3
What is AbstractQueuedSynchronizer in Java's concurrent.locks package used for? Can someone shed some light on its methods doAcquireInterruptibly and parkAndCheckInterrupt?
Bronnie asked 10/3, 2012 at 7:52
3
Solved
I have a number of default methods in interfaces that need synchronization and it seems that only this is available:
default void addUniqueColumns(List<String> names) {
synchronized (this) ...
Crittenden asked 1/12, 2013 at 11:27
0
What is the main idea of synchronized method and synchronized block in Java?
And why should we use them?
Sample code would be nice. I have read the Java documentation about synchronized met...
Nassir asked 25/11, 2013 at 1:12
3
While reading concurrency in Java, I have following doubts:
Does Java provides lower level construct then synchronized for synchronization?
In what circumstances will we use semaphore over sync...
Tharpe asked 4/6, 2013 at 0:30
6
Solved
I commented earlier on this question ("Why java.lang.Object is not abstract?") stating that I'd heard that using a byte[0] as a lock was slightly more efficient than using an java.lang.Object. I'm ...
Rimmer asked 22/1, 2010 at 20:54
4
Solved
I have a very simple code but unable to understand.
public class Test extends Thread {
public synchronized void testPrint() {
System.out.println("I am sleeping..."
+ Thread.currentT...
Genovevagenre asked 1/11, 2013 at 5:28
3
Solved
public class ThreadA {
public static void main(String[] args){
ThreadB b = new ThreadB();
b.start();
synchronized(b){
try{
System.out.println("Waiting for b to complete...");
b.wait();
}ca...
Chancey asked 23/10, 2013 at 9:15
© 2022 - 2024 — McMap. All rights reserved.