Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird ThreadSafety issue with 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 » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird ThreadSafety issue with "create(String[])" method" Watch "URLyBird ThreadSafety issue with "create(String[])" method" New topic
Author

URLyBird ThreadSafety issue with "create(String[])" method

Alan Mehio
Ranch Hand

Joined: Apr 04, 2005
Posts: 73
Dear All,
The create method above is not thread safe since there is no synchronization on the method. I have opted to leave it as it is and mention in the "choices.txt" what will happen if two thread tries to create
a record on the server; please notice this is applicable when the application is running in a network mode. Now I can add a synchronization method and it will prevent any two threads from entering the method at same time ; hence overriding each other. Any way, my point here is to explain the
uncertainty in this method rather then to make the method perfect.
I need your valuable feedback concerning "KNOWING THE THREAD SAFETY ISSUES". I wanted to make a point in my �choices.txt�

Many thanks
Alan Mehio
London


Regards,
Alan Mehio
London, UK
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

The create method above is not thread safe since there is no synchronization on the method

Why not?


SCJP, OCMJD, OCMJEA
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Alan,

This issue is depending on your architecture more precisely on your server architecture, by example you choose to have a more data Data instance(I here I presume that the Data class owns the create(String[]) method)then the synchronized the useless. What is really important is that the file hander - the class which read/write your db file has all the important method synchronized.
If two threads access in the same time your create method and and your "physical write" is synchronized then you can let the create unsynchronized.
And a final note, may be I am wrong, is not such a good idea to have the Data methods synchronized because the the LockManager is responsible for the "thread handling".

Regards M.

[ September 22, 2006: Message edited by: Mihai Radulescu ]
[ September 22, 2006: Message edited by: Mihai Radulescu ]

SCJP, SCJD, SCWCD, OCPJBCD
 
wood burning stoves
 
subject: URLyBird ThreadSafety issue with "create(String[])" method