• 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 RAF multiple instances

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,
This is my first post but I have been reading quite a bit around here.
I am planning on implementing my code around multiple raf instances but I have one concern. If I have two threads each with their own RAFs and one adds a record to the RAF, is the other thread's RAF automatically aware of the write? Or will the RAF file pointer be out of wack?
I did consider just using one static instance for all threads but I can't think of any benefit.

Thanks,
Mike
 
Author
Posts: 65
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this concern, I'll add another related question.
I do see a strong benefit in working with one static RAF - the simplicity. Simplicity in multithreading, simplicity in not managing pool, etc. That means, at least for a lamer like me - less bugs.
Well, here is the question - why not? I can't argue that it hits performance, but as I got it, performance may be sacrificed for the simplicity according to the "holly document" - the assignment instructions:

A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient.

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike, very welcome to JavaRanch and SCJD forum

Originally posted by Mike Grandmaison:
Hi Everyone,
This is my first post but I have been reading quite a bit around here.
I am planning on implementing my code around multiple raf instances but I have one concern. If I have two threads each with their own RAFs and one adds a record to the RAF, is the other thread's RAF automatically aware of the write? Or will the RAF file pointer be out of wack?

Let's consider having mulitiple raf instances. In this case, mulitple threads/clients can read/write/update to the file at a same time. But utmost care should be taken that no two raf instances are working on same record. This is where the concept of locking comes into picutre -- To protect database file from corrupting.
And to answer your question, I'm not very sure if it reflects in another raf instance if you keep the connection open to file. If you close and re-open then it will surely reflect.
And there are other constraints too in using multiple raf instances. I wrote some which came on top of my head.

I did consider just using one static instance for all threads but I can't think of any benefit.

One static raf instance in Data and synchronize on that instacnce while doing database file manipulation == life made easy compared to mulitple raf instances.
Good Luck.

Thanks,
Mike

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am planning on implementing my code around multiple raf instances but I have one concern. If I have two threads each with their own RAFs and one adds a record to the RAF, is the other thread's RAF automatically aware of the write? Or will the RAF file pointer be out of wack?


if you have multiple RAF's then reading/writing to/from one RAF won't affect the fp locations of any of the other RAF's.
if write operation is done on one of the RAF's, then all the other RAF's will "know" about it, because they all read/write from the same file. just make sure they are not reading/writing to the same place at once.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,
Welcome to JavaRanch and this forum!

I am planning on implementing my code around multiple raf instances but I have one concern. If I have two threads each with their own RAFs and one adds a record to the RAF, is the other thread's RAF automatically aware of the write? Or will the RAF file pointer be out of wack?


Other RAF instances won't be "aware" of records added by others, but they don't *need* to. For each read or write, you'll have to compute a position in the file and use seek() anyway, the useful information to determine whether a given operation can be performed or not, being shared through the file itself.
About what Satish write:

But utmost care should be taken that no two raf instances are working on same record.


I'd like to add that only *writes* should be exclusive at the record level: allowing multiple threads to read the same record is OK, and even desirable.

Baruch:
I do see a strong benefit in working with one static RAF - the simplicity. Simplicity in multithreading, simplicity in not managing pool, etc. (...)
"A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient."


And that's why I think (and wrote already) that both designs are defendable: even if less simple, RAF connections pooling may be much more efficient.
Regards,
Phil.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,
Welcome to JavaRanch.
If you are having multiple RAFs, then you will have to consider how you handle creating new records.
You do not want two separate RAFs creating records, one overwriting the other.
Also all your other RAFs need some way of finding out that a new record has been created so that they can correctly search, display, and posibly book that record.
Regards, Andrew
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic