• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 284
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Why not?
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic