This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.

Frederic Thierry

Greenhorn
+ Follow
since Apr 16, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Frederic Thierry

I have implemented the "isLocked" method in the following manner:



I was wondering how you guys decided to then use this method inside your bussiness logic. Did some of you just implement it and did not use it at all. Or can we use this method prior reading or finding data to enhance record locking on the client side?

Thanks for your responses.

Fred
[ May 06, 2008: Message edited by: Frederic Thierry ]
So Edwin what you are trying to say is that we should not synchronize the CRUD methods. We should use the lock mechanism for both update and delete (create is not really an issue). That is a good idea but we would then end up with dirty reads.
Well I will let my reading side of things be concurrent and I will make sure that the writing is threadsafe (Hence readers will be able to read records in parallel on a multiple processor machine unless a writin process is taking place.). I rather prefer my users to see the correct data and wait a tiny bit longer.
Edwin, you are totally right about filtering. I am doing the B&S assignment hence the 48 hours does not apply to my design. But if one decides to delete one of the records then in my code logic I remove this record out of my map.

Alexander, you are totally right if we are running the code on a single processor. It will take about the same amount of time (we have to take into account the overhead for threading but its really small). The scheduler does indeed provide time slices for each thread (kind of some context switching between threads).

On the other hand if a multi processor machine was being used, then each piece of code could be running on a seperate processor hence that could improve the performance. But that I believe is out of scope for the project. I think it is best to write the code for a single processor machine.

Basically, I have also tried to come up with a solution where reading and writing takes place on the record level but has Alexander stated this seems to be currently not possible. If it was, I think someone might have already found such a solution on the forum. Plus I think it would make the code extremely complex. The only thing I am still scratching my head about is the "isLocked" method. I am wondering if there could be a way I could use it to improve my concurrency with the CRUD methods.

By the way Mohamed, I am doing the B&S which also requires us to book a contractor. Now we do need to use the update method for booking so we can write to the "owner" field (might be a different field for Urly assignment). But when it comes to the Actual booking logic (i.e. Contractor or Room already booked so cannot be booked again) I believe this should be implemented on the client side. I think it is best to keep the "Data" class, or its subsystems if you are using a Facade pattern, as generic as possible. Hence my methods just fulfill the requirements described in the given interface and not more. I will build a thick client that will then provide the bussiness logic.
[ May 03, 2008: Message edited by: Frederic Thierry ]
Ok at the moment the file contains 27 contractors. Ok let's say you have a 1,000 contractors present in the file (that is a large number), well from monkhouse's book 1000 records uses about 10MB of RAM. Hence as he points out this should not be a problem on most computers since they have at least 128MB of RAM. I also feel that using this Map then makes my code much neater. Hence, yes as I had stated earlier once a write operation is taking place all other threads will be in a blocked state until the lock is released. The main advantage with the readLock is that if no write operation is in place then all threads are allowed to read and find records.

I am actually at this very moment wondering whether there is a way I could make the "isLocked" method more useful in my code. Maybe the way to go about this would be to call up the isLocked(recNo) method prior reading a record. Any of you guys have any idea how this method could be of use.
Simple Edwin I first off populate a Map with the Records in my constructor. Hence I use a simple readLock around this Map when client try to read the records. Now when someone is updating or doing any sort of writing to the file I have decided to use a writelock. This is to stop the possibility of dirty reads. Plus both find and read methods allow for a quick read of my Map cache. I prefer my users to see the right information and loose some performance (bare in mind that my reading performance is much quicker than reading directly from the file).

You seem to want to allow a user to read record 5 whilst another is updating 6. That is great idea but then how do you stop a user from reading record 6 if this record is also being updated?
It is possible to have a single static RAF instance. And a lot of people have been iplementing either a singleton Data class or underlying singleton subclasses (LockManager and FileAccess classes). Now if the data class or FileAccess are singletons then you will have a single RAF object whether it be static or not.
Congrats on your great score.
I am trying to decide on my record locking technique and the "hand-over-hand locking" method presented in Monkhouse's book seems to fully fulfill word for word my following assignment requirement:

"If the specified record is already locked, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked."

Do any of you know whether there would be another way to fulfill this requirement? I am just a bit worried that this technique might be considered too complex for a junior developer to understand. Anyone out there used this famous "hand-over-hand" locking method and obtained the magical 80/80 score?

Thanks for all replies.

Fred
A "no show" means you never showed up to the exam, hence prometric never received your grade. I would contact prometric ASAP if I were you. I believe they never received the result from the testing centre. You might need to send them your printed scores to show them that you passed the exam.
Oh actually I have decided to use stAx, because I need to create a large XML file. SAX cannot write and DOM is not the best soluion with large files.
Hi,

Does anyone have any ideas on what the best API for writing XML1.0 to a file.
I am aware of SAX, JAXP, StaX and DOM however I not sure which would be the simplest to use to create a simple XML file. Has anyone out there had any experience using any of these API's, your recomendations will be really appreciated.

Thank you.

Fred
Hey Guys,

I have had long think about your current topic. AJay is right about the following:

each new client gets a "new" instance of DvdFileAccess

that is the static "database" variable points to a new Instance of DvdFileAccess when a DvdDatabase instance is created.

Now Lets look at the DvdFileAcces class on page 138 and 139. You will notice that there is a difference between the code in the book and the code you download from the APress website. In the book the "RandomAccess database" variable is static whereas in the source code it is an instance variable. Also in the source code Andrew uses the database variable for the conditional block of code inside the DvdFileAccess Constructor whereas in his book he uses the dbPath varaible("static String dbPath").

So as you can see those are two errors either on the source code side or in the bok.

OK lets assume the "RandomAccess database" varaible is static and the varaible used inside the DvdFileAccess constructor used is the database variable, well the setting of the database will only occur once. If dbPath is used then the database will only be set once too.

Andrew if you pass by this forum can you please clarify the inconsistency between your source code and the book code on page 138-139.

Thats as much I can bring to the table.

Oh by the way, I think the constructor in the DvdDatabase File will have no effect since the import variables in the DvdFileAccess class are mostly static plus the database setting will only take place once.

Hope I was clear enough.
It is still highly applicable since there hasnt been any massive changes in Java 1.6 compared to 1.5 apart from the GUI framework side etc.... I will advice you to use Andrew's book since he covers important topics such as multithreading and especially locking.
Concerning your 2nd question (being able to view binary file), you can use a free binary hex editor such as "Free Hex Editor Neo" to view the file. It will display the hexadecimal bytes and its corresponding characters.