Results 1 to 7 of 7
Thread: synchronized(this){}
- 03-13-2012, 01:41 PM #1
- 03-13-2012, 01:53 PM #2
Re: synchronized(this){}
The question is asking, why can't the compiler remove that, since it appears to do nothing? Presumably, the compiler can remove empty statements and code that won't be reached. Why can't the compiler remove that statement?
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 03-13-2012, 02:03 PM #3
- 03-13-2012, 02:18 PM #4
Re: synchronized(this){}
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 03-13-2012, 02:31 PM #5
Re: synchronized(this){}
Okay, let's do it this way :)
Here are my thoughts:
the synchronized keyword makes it sure that there could be only one read/write operation at a time... so it might be the case that synchronized(this) synchronizes the current working object for I'm-not-sure-what-context and does it even if that block is empty...
Is it super-stupid, or not that bad?
Thanks,
Zs.
- 03-13-2012, 02:41 PM #6
Re: synchronized(this){}
Kevin,
I had lunch, I've been thinking on this...
Here are my thoughts:
Given a point in time where we are at the line synchronized(this){}. Now, all previous locks has to be released, so this line basically does nothing, but separates code before and after it. I've never seen this in practice, though.... Am I closer?
Zs.
- 03-21-2012, 02:08 AM #7
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Problems with synchronized
By BigHotCuppa in forum Threads and SynchronizationReplies: 3Last Post: 11-20-2010, 08:11 PM -
Difference b/w "synchronized","synchronize",and "synchronized()"
By Bala_Rugan in forum New To JavaReplies: 1Last Post: 09-08-2010, 04:08 PM -
Synchronized(this)?
By kiza in forum Threads and SynchronizationReplies: 10Last Post: 04-07-2009, 01:20 PM -
synchronized
By bugger in forum New To JavaReplies: 2Last Post: 11-28-2007, 10:33 AM -
doubt about synchronized
By simon in forum Advanced JavaReplies: 2Last Post: 08-05-2007, 03:49 AM
Bookmarks