Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking mechanism and maximum number of records in the "database"

 
Dinesh Mungra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
My intended locking mechanism uses two arrays:

one is an array of record token objects to lock on, one for each record in the database.

The other is an array of lock cookies, which are longs that identify a
client; also, one cookie per record.

I have two choices:A) use ArrayLists and don't worry about the size;
B) use arrays, but then I have to know the max nr of records.

Option A has the following drawbacks:-- performance is lower than with arrays, and you want the waiting time for other threads to be as short as possible
- and if I additionaly use Java 5 Generics, the code is better but the performance will be even worse.

Option B forces me to assume a max nr of records. It does perform better, but I still think it's barbaric.

Will it be a problem if I just make an assumption about the max nr of records and let the app throw in the towel when that number is reached?

Have any of you encountered this dilemma? What are your thoughts on this?
 
B Chen
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except for embedded systems, I generally avoid having such limitations like "max number records" in my programs. For one thing, it complicates the code with addition checks for these self-imposed limits. Performance may be slightly better, but its not worth it. Computing power gets cheaper every year. It cost more for developers to do extra hand-coding to squeeze out every bit of performance possible.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really think using Collections and generics will give you major performance problems which are so severe that they outweigh the restrictions you place on yourself if you don't use them you might want to learn some basic programming skills.

In other words, don't even think of not using the tools provided for you in the standard library.
[ June 22, 2006: Message edited by: Jeroen T Wenting ]
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys


I don't think that your dbs are designed for a very big number of records.
A small tip : if you have a counter (locks or records) take care of the silent wraps around


But once more, I don't think that the URLyBird (or BS) is a suitable solution for a such amount of records.


Regards,
Mihai
 
Dinesh Mungra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that performance should not be an issue, however, the assignment itself implies that arrays be used for the data. No Lists or Collections there. Does that mean that Sun's Exam creators lack basic programming skills too? There may be a valid reason for that choice, for instance to lighten RMI traffic. I would also like to point out that in the Generics and Autoboxing/unboxing tutorials Sun itself states that such code degrades performance. We are talking about code that
will be used inside a synchronized block, which other threads will have to wait on.
But again, I agree that for this assignment, performance should not be a serious issue. I was only wary that Sun may not like this approach in my completed assignment.
 
Tom Nicki
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that performance should not be an issue, however, the assignment itself implies that arrays be used for the data. No Lists or Collections there.


Hi Dinesh,

I my assignment there is nothing about arrays/lists/collection.
Can you post the part of your assignment which says about it?

Tom
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The assignment implies nothing.
The interface returns an array from the search function because it's very easy to do so and easily transferred over a network connection, that's all.

The Collections framework and especially the List classes are specifically designed for situations in which the amount of data isn't known when you start filling it, which is what you have here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic