• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

B&S: Lock file with Channel

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

So, I'm writing my choices about the Lock and I have a doubt...

My solution use the Channel to Lock the database file to restrict at one access for time... I specifys...

When application run as Server & Client (run the server and run some client), the Server lock the database, and, if I start the application in Standalone mode too, I throws an Exception with "File alredy open..." (my choice)

The Server can receive any number of Client's connection... The Standalone can execute only one for time...

Its a BAD???

Hi Laura
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Laura,

My assignment clearly says (and i guess yours too):


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.



So using a Channel to restrict access to database file is not necessary and you are doing more than you should do. You will nog get any extra points for doing so, only get points deducted if you made a mistake or if you have very complicated code for doing that.

And it's totally ok for your standalone application to be executed only one time, because there is at most 1 program accessing the db-file. So it's your standalone application or your server application or another application that's using that database-file.

Regards,
Roel
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Laura, if I am correct the Channel you are referring to is in the java.nio package which is not allowed for the SCJD. And the instructions clearly stated "assume only one program assess the database file at any moment".

All I have said in my choices.txt in my assumptions is something on the line:
* The stand-alone version and networked version will not run at the same time on the same computer

The only lock issue you do need to worry is the record locking (eg those lock, unlock, isLocked methods). What you are doing with Channel is more of file locking which can be assumed.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang,

It's clearly in the assignment, so i guess you don't have to mention anything about it in choices.txt

K. Tsang wrote:The stand-alone version and networked version will not run at the same time on the same computer



And if i am really picky: if they both use a db-file that's on the same network as the both computers, you still would have a problem

Regards,
Roel
 
Hey! You're stepping on my hand! Help me tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic