aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird Requirement Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird Requirement Questions" Watch "URLyBird Requirement Questions" New topic
Author

URLyBird Requirement Questions

Thomas Paul Bigbee
Ranch Hand

Joined: Jun 28, 2005
Posts: 71
Greetings all;

I have known several people who have failed automatically for not following, or, misinterpreting a �Must�. Unisys does not reimburse a failing grade, so, with that in mind, I have several questions and would appreciate any feedback, whatsoever.

I�ve been given the URLyBird Application to build.

"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."

Does this mean that I cannot perform any polling of the users waiting on a lock every N seconds, or can the wait timeout without the resource becoming available?


Is it acceptable to lock the entire database while operating locally, even if there are remote users already on the system, when the remote users are not holding any locks?


Can the Server already be started on the �local server� before any remote users try to log in? I didn�t think it was possible to start another process on a remote machine.


I am using List recordLockList = Collections.synchronizedList(new ArrayList)) as a thread safe was to keep my RecordLock objects (record number, user session id), a J2EE friend of mine suggested that I keep an external file and write locked records into it, which way is better, and am I allowed to even write to an external file?


Thank you, Tom Bigbee
Data Architect, Unisys
[ June 29, 2005: Message edited by: Thomas Paul Bigbee ]
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Tom,

welcome to JavaRanch and to this forum. Your fear for automatic failure is justifiable . In my case, I am also afraid to kiss my 420 Euro.

Concerning your questions:

Have you decided what road you go, Socket or RMI?

Further, I think that locking the whole database while only one record should be locked is somewhat brutal isn't it?

What do you mean by "local server". You must always start your server by hand with Sun's given command line. You start your server always on the machine that is supposed to be the server. That can be the machine in front of you or any other you can reach over the net. But you always start the server manually.

Last but not least, I don't see the benefit for an external file. You are not going to make anything persistent, so why having an external file?

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Thomas,

Welcome to JavaRanch and this forum.
"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."

Does this mean that I cannot perform any polling of the users waiting on a lock every N seconds, or can the wait timeout without the resource becoming available?


Cannot is a bit strong here - the instructions do not specify a "must" condition, but rather a "should" condition. So you could poll the users waiting on the lock every N seconds if you really wanted to.

Why do you want to though?

Is it acceptable to lock the entire database while operating locally, even if there are remote users already on the system, when the remote users are not holding any locks?


This scenario should never occur. Check your instructions for text along the lines of "You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server". In other words, you cannot be running locally (java -jar runme.jar alone) at the same time as you are allowing remote users access by running a server (java -jar server).

Even if you could, I do agree with Darya that logically locking the entire database is not something you want to be doing - you are blocking all the other users.

If you are talking about physical locking (ensuring that only one thread is physically accessing the data file at any given time), then you are going to have to perform that lock in multi user mode, and since the same Data class will be used for both multi user and single user, you will, by default, lock the data file in single user mode .

Can the Server already be started on the “local server” before any remote users try to log in? I didn’t think it was possible to start another process on a remote machine.


As Darya said, you have to start the Server from the command line. So, yes, it can be started before any remote users try to log in.

And you are correct - it is not possible to remotely start an application. (There are all sorts of caveats on this, such as having a "master server" start minor servers when they receive a given command (think of remote control of a J2EE application server) or using inetd on a Unix server to start a Java process. But none of these caveats apply to the SCJD assignment).

I am using List recordLockList = Collections.synchronizedList(new ArrayList)) as a thread safe was to keep my RecordLock objects (record number, user session id), a J2EE friend of mine suggested that I keep an external file and write locked records into it, which way is better, and am I allowed to even write to an external file?


I think that you would be allowed to write an external file if you wanted to. But what benefit will it give you?

One possible reason could be that it would allow you to determine which records were locked following an application or system crash. However if the application or system crashed, then the clients would be disconnected anyway, so this would be of little value (IMHO).

If the data you were storing in your collection was large, then you could (theoretically) store more of this data on the hard drive. But take a look at what you are storing in your collection - is it really so large? How many locks would you need to be storing in the collection before you started to be concerned about the memory usage?

What other reasons do you (or your friend) have for suggesting storing to file?

Just on the subject of your synchronized access to the collection - presumably you are verifying that a RecordLock object does not exist in the collection for the record you are trying to add before you perform the actual adding. If so, would you agree that the two steps you are performing on the collection should be atomic? If so, does it make sense for the collection itself to be synchronized?

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Even if you could, I do agree with Darya that logically locking the entire database is not something you want to be doing - you are blocking all the other users.


Ok guys just want to clear something up here.
Locking the entire database...I have seen ppl talking about locking the DB when they are doing for example create() to ensure integrity of the operation.
Where do you stand on this ?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Alan,

Very good question.

You do need to ensure that only one thread can create a record at any given time. But what sort of lock to use?

Logically locking the entire database would require the thread creating the record to wait until all other threads have released any logical locks.

Physically locking the create method can operate outside of any other locking scheme, so only other threads calling the lock method would be affected.

I deliberately haven't given my answer to this question - I have just given you a couple of ideas to think about. Can you see benefits / problems with either concept?

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLyBird Requirement Questions