Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: Design question ...

Jim Wallace

2003-07-15

Replies:

Hi,
 
I might not understand your requirements properly.   However -
 
A:
 
If your lockKeywords method is simply trying to update the database entry to "locked" status, and returns either success or failure, it should still be capable of being made to work in a distributed environment.  You don't need to synchronize it, as your database resource manager should enforce consistency through its locking mechanism.  Provided you have your isolation level set to READ_COMMITTED or higher.
 
The downside of this is that the status is only available in the database, and you have to make a call to the database each time a user needs to lock a module.  If a large number of these requests are being made, and a reasonable proportion of them result in failure because the database is already locked, it might make sense to have your update preceded by a read. 
 
You could always wrap this in a stateless session bean.  Naturally you require some means of reseting the database if a session locking the database crashes, or if a user fails to execute the unlock process. 
 
B:
 
The alternative is to go to some kind of distrbuted solution using RMI.  It is not that difficult to implement, in the basic case,unless your application has high availability requirements and you need to think about failover.   My feeling is that, unless your application usage patterns are unusual as compared to that of a typical content management solution, the RMI approach may not enhance performance enough to make it worth the work.  This would be especially true if you need to keep the lock status in the database.  On the other hand, if you can eliminate the requriement to use the database, it solves the reset issue.
 
C:
 
The singleton approach that Martin suggests could also work.  It is a practical means of distributing read only data that is centrally maintained (application configuration data, for instance).  To use it in this kind of situation with a database, you probably would want to have each Singleton attempt to update the database directly, rather than relying on the messaging backbone.  So the process would work like this.
 
1)  The client checks the singleton lock status for a particular module.
2)  If the module is not locked by another user, the singleton attempts to update the database (lock the module for the client).  If this fails, the client is informed the module is unavailable; if it suceeds, the client is allowed to begin editing.
3) If the lock attempt succeeds, some kind of process will be undertaken to notify the other singleton instances in the cluster that the indicated module is now locked.  This could be done by having the locking singleton issues a publish/subscribe msg via JMS.  Or you could have a central message producer activated by a trigger on the database. 
 
The main advantage of option C over A is that the probability of failure on the locking call is reduced.  This could be a significant issue if there is a lot of contention among users for certain modules.  Otherwise, it is probably not worth the effort, unless there are additional uses for the distributed singleton.
 
Cheers,  Jim W
 
 
-----Original Message----- "From: An interest list for Sun Java Center J2EE Pattern Catalog [mailto:J2EEPATTERNS-INTEREST@JAVA.SUN.COM]On Behalf Of Martin Zuzcak
Sent: July 15, 2003 7:31 AM
To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Subject: Re: Design question ...


hi,
see singleton in cluster, you can resolve your problem similar way
http://www.javaspecialists.co.za/archive/Issue052.html

martin



Rafal Kedziorski <rafcio@POLONIUM.DE>
Odeslal: An interest list for Sun Java Center J2EE Pattern Catalog <J2EEPATTERNS-INTEREST@JAVA.SUN.COM>
13.07.2003 13:09
Odpovězte prosím uživateli An interest list for Sun Java Center J2EE Pattern Catalog
       
        Komu:        J2EEPATTERNS-INTEREST@JAVA.SUN.COM
        Kopie:        
        Předmět:        Design question ...



hi,

I have a small design question for our problem which is working on a single
instance of an appicaltion server. we are working with JBoss 3.2.2.

Our application - multimedia content management system - is an modules
based application. You can store media files with partient mata data. You
can admin category trees and keywords. If some user want for example edit
categories or keywords, this module will be locked for this user for the
duration of the edit session. our lock is working on a singe instance
without problems. how we do this. we have this method:

public synchronized boolean lockKeywords(Long user_id, Integer mandant_id,
Long project_id)
  throws CreateException, ProjectException {
  ...
}

for each module we writes a history (created, changed, removed, locked,
unlocked, ...) to the db. this table we use for locking. we are searching
for the last unlock. id we found one, than the module can be locked for the
given user.

but this wan't works in an cluster environment. are the a pattern, which
can we use to solve our problem? or should we user other implementation?


Best Regards,
Rafal

====================================================================
Community Web Site (Core J2EE Patterns Catalog - Online Version):
http://java.sun.com/blueprints/corej2eepatterns
Getting Started (Beta Version):
http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/
Get the book:
http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20
List Archive:
http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing:
email "signoff J2EEPATTERNS-INTEREST" to listserv@java.sun.com


©2008 junlu.com - Jax Systems, LLC, U.S.A.