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

Can anyone help me with this?

 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my SCJD assignment and it says:

<--
.....
The program must be able to work in a non-networked mode. In this mode, the database and GUI must run in the same VM and must perform no networking, must not use loopback networking, and must not involve the serialization of any objects when communicating between the GUI and database elements.
.....
.....
When you submit your assignment, each part (client and server) must be executable using a command of this exact form:
java -jar <path_and_filename> [<mode>]
.....
.....
-->
So if i want to start multiple non-networked GUI,I have to type "java -jar [jar_file_name] alone" multiple times.But this will start multiple JVMs(each JVM corresponds to
one "GUI+database access").The problem is,how can we lock/synchronize an object/record accross multiple JVMs?Conventional locking strategies don't seem to
be working here.Have i missed anything?Any help will be much appreciated.
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the locking will only affect ONE Server with multiple Clients, not several client-server instances
 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand.The spec says you must not use serialized/sockets code in a non-networked mode.
My interpretation is I could only start a separate JVM each time when the user type "java -jar [jar_file_name] alone"
(this will start a GUI+database access function within an independent JVM).Consequently,I have to
perform locking across multiple JVMs.How could you have a single server instance shared between different
JVMs without using RMI?Could you please give more explanations?
 
Andriy Pererva
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, liang!
I think you have overcomplicated your SCJD solution. All the locking logic applies only to "single server - multiple clients" mode. Assignments assumes that you will not try to do so perverse action as starting multiple instances of standalone application on the same database file.
It would be better if you explicitly prohibit to run more then one instance per data file of both server and standalone client. For example you can create file, like [name_of_your_datafile].lock in the same directory as your data class when starting your instance, and remove it when exiting. This lock file will indicate to other instances that the data file is currently in use of another instance
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Weiliangsolutions,


I'd strongly suggest you run the Denny's DVDs example in the Andrew Monkhouse book.

The assignment is meant to be a client/server application with one server and multiple GUI clients where you will have multiple JVMs: one running the server code and 1 or more running the GUI client code communicating through the network with the server.
Here you would start 1 JVM with the -server flag and all the others the GUI clients with no flag when you start the JVM(s).

When using the -alone flag, it is standalone and both GUI client and Data Server runs in the same single JVM and no networking code should run. Otherwise it will fail because you are
violating a MUST requirement.


Hope this helps,


Carlos.
 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andriv,Thank you for your reply.
For my assignment,the spec has given me an interface for which I must
implement:

public interface DBMain(){
....
public void update(int recNo,String[] data) throws RecordNotFoundException;
....(and so on)
public void lock(int recNo) throws RecordNotFoundException;
public void unlock(int recNo) throws RecordNotFoundException;
....
....
}

This apparently indicates I have to lock a paticular record for both remote and local
access.(So i can't create a file to indicate my data file has been locked because this will,
effectively lock all records,which is apparently not the examiner wants because it will
introduce read/write overheads).
You have mentioned "one server,multiple clients",my question is: when different users(locally)
type "java -jar sampleproject.jar alone",they will inevitably result in different JVM(because this is the
spec says i must do).There is no easy way i could synchronize/lock a particular record across
different JVMs.
Remotely i am OK,because once i have put my data access instance in the remote registry,
different clients will invoke the same data access instance via a remote stub,thus it becomes
"one server,multiple clients",but how can you achieve this in a local context without using RMI
registry/sockets (which are prohibited)?

 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p.s.
Locally you would have trouble,because unlike using registry(in which only a
single instance is registered),locking a particular record
requires you to lock something across different JVMs(different clients).
Suppose you have both a remote and a local client accessing the data file,
how would you perform locking?That's what seems entrangles me.Any more helps?
 
Ehsan Rahman
Ranch Hand
Posts: 59
Chrome Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
weiliangsolutions liang wrote:Hi Andriv,Thank you for your reply.
... my question is: when different users(locally)
type "java -jar sampleproject.jar alone",they will inevitably result in different JVM(because this is the
spec says i must do).


Does your spec state anything similar to the following? :

"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."
 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah,that's exactly what my spec says.
Locally how would you construct strictly one server instance
serving different threads comes from different JVMs?
 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p.s.The spec also says:
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above...

Locally concurrent clients could come from different JVMs,right?
Have I missed anything?
 
wei liang liang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK,I have a touch with what people says here...
Requests from different JVMs will be interpreted as "different programs",
therefore i may assume at any instance requests could only comes from
one JVM but different threads.
Am I right?
Thanks everybody's help.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"weiliangsolutions liang",
you need to check your private messages urgently if you haven't done so yet (the "My Private Messages" link at the top of the page). Your account is about to be closed.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi wei,

This is how different modes should work:
  • standalone mode: database code (data class) + gui code are running in 1 JVM (of course not using your network code)
  • networked mode: database code (data class) is running in 1 JVM (on computer A, this is your server). the gui code runs in another JVM (can be on computer A, but also on a different one). each client (that will connect to your server) runs in its own JVM.

  • so if you want to test your code for example and you want to start a server and 2 clients, you will have to start 3 java commands and you'll have 3 JVMs running: 1 for the server and 1 for each client. These can be ran on the same pc (localhost), that's what I did to do some tests. But of course you can run each application (server and 2 clients) on a different computer.
    Each client represents a "thread" and your server must be capable of handling multiple concurrent requests (thread-safe) of these clients (and that will be the hardest part of your assignment in my opinion).
    So always there will be at most 1 application modifying/accessing the database file: in standalone mode there is just 1 all-in-one application. In networked mode your server application will access the database file and the different client applications will communicate with the server to get a list of records (rooms/contractors) or to update a record (making a booking)

    Hope my explanation helps to clear your doubts!
    Kind regards,
    Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic