synchronized Questions

3

Solved

Is it that monitor in Java does not restrict access to instance variables and only to the methods which are declared synchronized or code in synchronized statements? I have created two threads, th...
Thalamus asked 21/1, 2013 at 20:57

4

Solved

I think I know this, but would like it confirming. Obviously the synchronized blocks other threads from accessing it, but I see and awful lot of examples such as public synchronized void setValu...
Diagnostics asked 9/1, 2013 at 18:17

1

Solved

I want to have a boolean to notify some sections of the system that a specific service started. For some strange reason I'm getting the error java.lang.IllegalMonitorStateException: object not loc...

3

Solved

I have two methods: a() and b(). While I'm fine with multiple threads accessing any of the methods at the same time (that is desirable), I do not want any threads to enter a() while b() is being ex...
Connell asked 10/11, 2012 at 9:7

3

Solved

The point of this question is to illustrate that Java is not working as I expected. How would you expect the following code to behave? public class SynchTester { private static SynchTester synch...
Tartarean asked 2/11, 2012 at 15:0

5

We are running into an interesting issue that we noticed while doing stress testing of our system. We are using log4j (in JBOSS) very heavily for our logging. Here is a naive example of some loggin...
Lexicon asked 18/2, 2012 at 18:32

4

Solved

I was reading a thread from CodeRanch saying that abstract methods could not be synchronized due to the fact that an abstract class cannot be instantiated, meaning no object to lock. This doesn't ...
Verbalize asked 9/10, 2012 at 17:57

3

Solved

List<String> list = new ArrayList<String>(); list.add("a"); ... list.add("z"); synchronized(list) { Iterator<String> i = list.iterator(); while(i.hasNext()) { ... } } and ...
Unreflective asked 29/8, 2012 at 16:2

1

Solved

When you have couple of synchronized blocks on an object (say) obj then how does Java check if all these objs are the same or different? For example: public static f() { synchronized ("xyz") { ...
Chartreuse asked 27/8, 2012 at 10:0

3

Solved

I have a synchronized Map (via Collections.synchronizedMap()) that is read and updated by Thread A. Thread B accesses the Map only via Map.keySet() (read-only). How should I synchronize this? The ...

2

Solved

I'm preparing for an exam and after going over some sample exercises (which have the correct answers included), I simply cannot make any sense out of them. The question (Multiple Choice): What a...
Halfbaked asked 4/2, 2011 at 15:14

4

Solved

From what I know and researched, the synchronized keyword in Java lets synchronize a method or code block statement to handle multi-threaded access. If I want to lock a file for writing purposes on...
Gatekeeper asked 15/8, 2012 at 19:49

4

Solved

When Synchronization is used there is a performance impact. Can volatile be used in combination with synchronized to reduce the performance overhead ? For example, instance of Counter will be share...
Cloud asked 27/7, 2012 at 4:10

4

Solved

I have experience this weird behavior of volatile keyword recently. As far as i know, volatile keyword is applied on to the variable to reflect the changes done on the data of the variable by o...
Cedillo asked 1/7, 2012 at 10:49

4

Solved

I've come across code like the following several times class Foo { private Object lock = new Object(); public void doSomething() { synchronized(lock) { ... What I'm interested in is why a l...
Snowfield asked 30/6, 2012 at 15:36

1

Solved

I scanned all the java documentation on the synchronized statements looking for an answer to this question with no luck. Say I have thread1, thread2, thread3 trying to run the following code all a...
Crackerbarrel asked 30/6, 2012 at 16:24

3

Solved

I have a class called "Account" public class Account { public double balance = 1500; public synchronized double withDrawFromPrivateBalance(double a) { balance -= a; return balance; } } an...
Forbid asked 17/6, 2012 at 18:38

3

Solved

Consider a primitive type variable with lots of threads reading and a few threads writing, will the following code work correctly? If it will, does it provide better performance than 1). declaring...
Syman asked 27/11, 2010 at 2:40

1

If I use @property (atomic,assign) int value; and later access it like so self.value--; is that decrement atomic? Because if I had to do this: self.value = self.value - 1; then I am sure ...

1

Solved

I have a Javascript object created as follows: var ccStatTracker = (function (){ ccmap:{ "1":["1","2","3","4"], "2":["4","5"]; } return { modifyCCMap: function (){ // Code which takes fol...
Harber asked 9/6, 2012 at 11:16

3

I ran the following code: class Counter extends Thread { static int i=0; //method where the thread execution will start public void run(){ //logic to execute in a thread while (true) { incre...
Topless asked 19/5, 2012 at 12:19

2

Solved

I have read that Thread.sleep() will pause the currently running thread for the time specified after which it goes back to runnable state waiting for it's turn to run. Also, if called from synchro...
Vend asked 19/5, 2012 at 9:19

6

Solved

I have started learning concurrency and threads in Java. I know the basics of synchronized (i.e. what it does). Conceptually I understand that it provides mutually exclusive access to a shared reso...
Adamsite asked 14/5, 2012 at 10:14

2

Solved

I have 2 TTreeviews. Both of them have the same number of items. I'd like to be able to synchronize their scrollbars... If I move one of them, the other moves also... For the horizontal, it works ...
Brut asked 9/5, 2012 at 23:5

5

Solved

I've been reading up on the Java Virtual Machine Instruction Set and noticed that when using instructions to invoke methods (e.g. invokestatic, invokevirtual, etc.) that are marked synchronized, it...
Kunkel asked 26/2, 2011 at 22:42

© 2022 - 2024 — McMap. All rights reserved.