This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Old FBN still kicking Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Old FBN still kicking" Watch "Old FBN still kicking" New topic
Author

Old FBN still kicking

Pep Menval
Greenhorn

Joined: Oct 31, 2003
Posts: 21
Hi guys, you are helping me a lot. I have some questions for you:
Sun spec wants de lock/unlock methods to be public, right? so it means they have to be called from outside the class. And I do it so. But, isn't a nonsense to call them from everywhere instead of calling them, say, from modify' Data class? About the lock(-1), when is it requiered. I call it before adding a new record and before shuting the server down, is that correct?
On the other hand, I have declared my HashSet holding locks as static, to be shared among every client, because they run in diferent VM, not just threads. Is that correct?
Besidesm the HashSet holds the record Integer as a key and this as the value. What do you think?
Finally, what about parameters passing to main. Do you feel it can count? My gui is pretty good and allows to open a remote/local connection at any time. But perhaps sun expects some paraments passing?
Thanks a lot


Thanks a lot
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 10816
    
  25

Hi Pep,
Originally posted by Pep Menval:
Sun spec wants de lock/unlock methods to be public, right? so it means they have to be called from outside the class. And I do it so. But, isn't a nonsense to call them from everywhere instead of calling them, say, from modify' Data class?

Being able to lock individual records makes it easier to add functionality at a later date.
For example if you wanted to book two connecting flights. If you cannot book either one, then the other booking is useless and you don't want it. A concrete case was when I lived in Holland, to fly back to Australia there was only one flight from Holland to London that I could catch in order to catch the flight from London to Australia. Earlier flights from Holland left before trains were running (and taxi to the airport was too expensive) or got me into London too late to catch the flight. So if I could not book both the Holland -> London flight and the London -> Australia flight, I did not want either.
This sort of capability is easy to do if you can lock individual records: you just lock both flights, check their availability, then update both and unlock both. Without this capability you would have to have some way of undoing one of the bookings if it failed (and some companies (especially hotels) do not like people making bookings and then cancelling them). Even airlines can get upset with that (if you book all the seats on the Concorde and then later cancel them ).
Originally posted by Pep Menval:
About the lock(-1), when is it requiered. I call it before adding a new record and before shuting the server down, is that correct?

Sounds good to me - I did the same.
Originally posted by Pep Menval:
On the other hand, I have declared my HashSet holding locks as static, to be shared among every client, because they run in diferent VM, not just threads. Is that correct?

I agree with the first part of your statement but not the "because they run in diferent VM" part.
The remote client does not need to have direct access to the HashSet containing locks, and you would find it very hard to share a single object across multiple VMs.
It is the server side code that will be updating the HashSet. There will be multiple threads on the server side that will want to lock and unlock records, but they will all be in the same VM.
So yes, having a static collection is a good idea, but the reasoning for it is slightly wrong.
Originally posted by Pep Menval:
Besidesm the HashSet holds the record Integer as a key and this as the value. What do you think?

Sounds good.
Which 'this' are you using? 'this' instance of Data class?
(there are more questions on that, but they depend on which 'this' we are talking about )
Originally posted by Pep Menval:
Finally, what about parameters passing to main. Do you feel it can count? My gui is pretty good and allows to open a remote/local connection at any time. But perhaps sun expects some paraments passing?

I allowed parameters to be specified on the command line, but they were not necessary: my client and server both worked fine with no parameters.
In the new assignments Sun have explicitly stated that the only parameters allowed are those that indicate the mode of the application ('server' to run in server mode, 'alone' to run as a stand alone client, and no parameters to run as a networked client). All other parameters that you might be thinking of putting on the command line (such as IP address, port number ...) must be configured in the GUI in the new assignments. So I think Sun prefer to have as few parameters as possible (but maybe one or two so you show that you do know how to handle command line parameters).
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Pep Menval
Greenhorn

Joined: Oct 31, 2003
Posts: 21
Hi Everybody,
Andrew, can you give me further advise over a few topics:
The way I implementent my server was through a Factory serving NEW remote instances upon every request. Thus, I assume they run in diferent VM. Is that assumption correct?
You are right, clients cannot access the HashMap containing the locked records directly since it is private. By the way, should the HashMap be syncronized itself. I don't think so cause it is handled in a synchronized block, but just to be sure.
What about the unlock instruction, to be sure it is done in any way, I put it in the finally clause of the try block. What do you think?
By the way, when resubmitting my assignment, do you know if I have to add a new text file explaining the changes I made, or just as usual?
By the way you made your last comment about parameter passing, seems to me that you have a class that can be run as server or as client according to command line paramenter. Is it so. I have diferent classes, server and client. How do you find this aproach? In this case are command line arguments still recommended?
Thanks to you all, specially to you Andrew for your precious time.
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Pep,
The way I implementent my server was through a Factory serving NEW remote instances upon every request

Sounds good.

should the HashMap be syncronized itself. I don't think so cause it is handled in a synchronized block

Correct.
By the way, when resubmitting my assignment, do you know if I have to add a new text file explaining the changes I made, or just as usual?

I don't know. I would put add a new section in existing file choises.txt, instead of sending an addiotional file.
By the way you made your last comment about parameter passing

I have done another assignement, so I can not answer it. Can anyone answer Pep?
Best,
Vlad
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 10816
    
  25

Hi Pep,
Originally posted by Pep Menval:
By the way you made your last comment about parameter passing, seems to me that you have a class that can be run as server or as client according to command line paramenter. Is it so.

No, I also had separate classes for the client and server.
What I was talking about above was that for the new assignments (Contractors and Hotels) then the candidate must have a single class that runs as server or as client according to command line paramenter.
Originally posted by Pep Menval:
I have diferent classes, server and client. How do you find this aproach? In this case are command line arguments still recommended?

This is what I had as well.
If you do not need command line arguments (because you indicated that everything can be set in the GUI, then don't worry about them.
Regards, Andrew
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Old FBN still kicking
 
Similar Threads
nx:All of URLy Bird 1.1.3 about read/write lock
FBNS: Locking records and whole DB
hi Mark! need your opinion. "lock()"
Threads and synchronization!!
Almost ready to hand up: Just cleaning up and have a few questions