aspose file tools*
The moose likes Threads and Synchronization and the fly likes synchronized block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronized block" Watch "synchronized block" New topic
Author

synchronized block

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635




In your opinion, If you compare these codes,What is differences, advantage of these?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

There's nothing we can say about that, because a lot of context is missing.

Please post an SSCCE, and TellTheDetails.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
I want to to compare these:




Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
What do you think is different?
They look the same to me.

Jim ...


BEE MBA PMP SCJP-6
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
What about these:





If you compare these,What differences you see?
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Again, what do you think is different?
What is your question?

Jim...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Jim Hoglund wrote:
What is your question?


Agreed. What is the question? Throwing out code, with "tell me about it" isn't very clear.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
It is said in some cases, It is possible that some threads,don't see the lock.I want to know how can this happened, and how to prevent this happened?
agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
There is no difference between object lockObject and object of 'a' objectofa, if your concern is related to sequence of thread execution. You can synchronize your code using any type of object as long as this object is shared among all threads. In you code example, If I understood, both objects 'lockObject' and 'objectofa' is accessible and shared by Thread1 and Thread2. Hence, execution path will be fixed and predictable.


Manoj Kumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronized block