File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronize the create method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Synchronize the create method?" Watch "Synchronize the create method?" New topic

Synchronize the create method?

Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Just wondering did anyone end up having to synchronize upon the create method? Found mine became quite complex using 2 caches and when running the multi-threaded tests, some threads overwrote each other. Would appreciate people's views.
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8393

Hi Mark,

I synchronized all methods, so also the create-method.

Kind regards,

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Nicolas Kal
Ranch Hand

Joined: Sep 09, 2009
Posts: 69

I have placed synchronisation blocks in the class that provides a means of communication between client and server(backend in the case of standalone). The blocks are synchronized on the Data singleton class lock.


SCJP 6.0 , SBCD (Preparing..),
MSc Enterprise Systems Development, BSc Computer Science
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

Nicolas Kal wrote:The blocks are synchronized on the Data singleton class lock.

Since the Data class implements the Singleton pattern, this approach can do the job as well.

I too synchronized all methods of the Data class.

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Matheus Mendes
Ranch Hand

Joined: May 15, 2007
Posts: 68
I did the same thing, synchronize all methods = )

The Death of one is a tragedy, but the Death of a million is just a statistic. Joseph Stalin

I agree. Here's the link:
subject: Synchronize the create method?
It's not a secret anymore!