Questions tagged [synchronized-block]
85 questions
0
votes
2 answers
Synchronization required on an object which should be singleton by convention
I want that only one instance of my class, Format1 should be returned through the class Engine:
public final class Engine {
private static Format format;
public Engine(final Param1 param1, final Param2 param2) {
Engine.format…

user1071840
- 3,522
- 9
- 48
- 74
0
votes
2 answers
Java synchronized statement
I need a threadsafe arraylist like this.
public class BookingList {
private List bookings;
public BookingList() {
bookings = Collections.synchronizedList(new ArrayList());
}
@Override
public void…

Vering
- 907
- 9
- 19
0
votes
2 answers
Is this synchronized block needed or not?
For this code in a multiple thread environment, is the synchronized(c) necessary?
SynchronizedCounter c = new SynchronizedCounter();
synchronized(c){
c.increment();
c.value();
}
public class SynchronizedCounter {
private int c = 0;
…

ling
- 1,555
- 3
- 18
- 24
0
votes
2 answers
ConcurrencyException
private static HashMap sFileInfoObjectList = new CacheLinkedHashMap();
public static synchronized FileInfo getFileInfoForProvider(...) {
FileInfo foundFileInfo = null;
(...)
foundFileInfo =…

David
- 3,971
- 1
- 26
- 65
0
votes
3 answers
This Code can Throw an IllegalMonitorStateException
void waitForSignal(){
Object ob =new Object();
synchronized (Thred.currentThread()) {
try {
ob.wait();
ob.notify();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
…

Pavan
- 1,219
- 13
- 15
0
votes
3 answers
Is a method thread-safe if the return value is declared/returned outside of a synchronized block?
public Foo getFoo(){
Foo foo = null;
synchronized(fooList){
if(fooList.size() > 0){
foo = fooList.remove(0);
}
}
return foo;
}
Since foo is declared outside of the synchronized block, does the potential…

user1329572
- 6,176
- 5
- 29
- 39
-1
votes
1 answer
the following example : synchronized Integer is invalid
myCode is following:
I want to know why zhangsan and lisi are both can print :
李四9锁对象:1522503870
张三9锁对象:1522503870
public class TicketConsumer implements Runnable {
private Integer i;
public TicketConsumer(int i) {
super();
…

River
- 9
- 2
-1
votes
1 answer
Mutex access of synchronized blocks
I have code that contains a synchronized block within a loop, something like that
while (true) {
synchronized (SOME_MUTEX) {
//some more code here
}
}
There is another thread that is running code that is synched with the same…

oded wolff
- 147
- 8
-2
votes
1 answer
Can we define synchronized block inside a synchronized method?
In java can we define synchronized block inside a synchronized method? If so please explain me with example

Karthik Reddy V V
- 82
- 2
- 4
-2
votes
2 answers
Does Java synchronized block work same with "this" and with a method parameter?
How Java synchronization behaves if a method parameter is used in the synchronization block instead of this keyword.
public void doSomething(final MyInterface iface) {
synchronized(this) {
// ... do some work
}
}
vs
public void…

Niranjan
- 2,601
- 8
- 43
- 54