Synchronizing access to resources in Java

Discussion in 'Java' started by dlugi, Oct 3, 2006.

  1. dlugi

    dlugi Guest

    Hi!!

    I would like to synchronize access to one resource with two different
    applications working in two virtual machines. Is there some technology
    which enable to block access to resources (e.g. file, network etc) -
    something like global semaphore.

    I consider to use JavaSpaces but this mechanism is very slow.
    So, has anybody similar problem??

    Thanks in advance.
    dlugi, Oct 3, 2006
    #1
    1. Advertising

  2. opalinski from opalpaweb, Oct 3, 2006
    #2
    1. Advertising

  3. dlugi

    dlugi Guest

    opalinski from opalpaweb napisa³(a):
    > How about putting the resource behind RMI?
    >
    > Perform synchronize in RMI call.
    >
    > Opalinski
    >
    > http://www.geocities.com/opalpaweb/
    >


    it's not good solution because RMI transfer byte code and methods of the
    object are invoked locally so two clients can call the same method and
    get access to resources in the same time
    dlugi, Oct 3, 2006
    #3

  4. >
    > it's not good solution because RMI transfer byte code and methods of the
    > object are invoked locally so two clients can call the same method and
    > get access to resources in the same time



    The methods run in remote virtual machine. You can lock there. Where
    the invocation happens and that parameters get serialized does not
    prevent that.

    Cheers,
    Opalinski

    http://www.geocities.com/opalpaweb/
    opalinski from opalpaweb, Oct 3, 2006
    #4
  5. dlugi

    dlugi Guest

    I found it on http://java.sun.com/docs/books/tutorial/rmi/overview.html

    "Advantages of Dynamic Code Loading
    One of the central and unique features of RMI is its ability to download
    the bytecodes (or simply code) of an object's class if the class is not
    defined in the receiver's virtual machine. The types and the behavior of
    an object, previously available only in a single virtual machine, can be
    transmitted to another, possibly remote, virtual machine. RMI passes
    objects by their true type, so the behavior of those objects is not
    changed when they are sent to another virtual machine. This allows new
    types to be introduced into a remote virtual machine, thus extending the
    behavior of an application dynamically. The compute engine example in
    this chapter uses RMI's capability to introduce new behavior to a
    distributed program."
    dlugi, Oct 3, 2006
    #5

  6. > "Advantages of Dynamic Code Loading
    > One of the central and unique features of RMI is its ability to download
    > the bytecodes (or simply code) of an object's class if the class is not
    > defined in the receiver's virtual machine. The types and the behavior of
    > an object, previously available only in a single virtual machine, can be
    > transmitted to another, possibly remote, virtual machine. RMI passes
    > objects by their true type, so the behavior of those objects is not
    > changed when they are sent to another virtual machine. This allows new
    > types to be introduced into a remote virtual machine, thus extending the
    > behavior of an application dynamically. The compute engine example in
    > this chapter uses RMI's capability to introduce new behavior to a
    > distributed program."



    These aspects do not prevent using RMI to lock a resource. The
    paragraph you quote, in short, says: "If you have two virtual machines
    and one has class file A and the other one doesn't the one that does
    can share the class file with the one that doesn't". The paragraph
    does not talk about instances of those classes. The paragraph is
    orthogonal to topic.

    Good luck,
    Opalinski

    http://www.geocities.com/opalpaweb/
    opalinski from opalpaweb, Oct 3, 2006
    #6
  7. dlugi

    dlugi Guest

    opalinski from opalpaweb napisa³(a):
    > These aspects do not prevent using RMI to lock a resource. The
    > paragraph you quote, in short, says: "If you have two virtual machines
    > and one has class file A and the other one doesn't the one that does
    > can share the class file with the one that doesn't". The paragraph
    > does not talk about instances of those classes. The paragraph is
    > orthogonal to topic.
    >
    > Good luck,
    > Opalinski
    >
    > http://www.geocities.com/opalpaweb/
    >


    Ok, you are right, I read this paragraph through. Thank you for your
    advices.
    RMI involves a massive overhead, but I need this mechanism to lock
    records in my implementation of database management system, so I search
    a little bit faster solution than RMI. I look for eguivalent of system
    semaphore in operating systems .
    dlugi, Oct 3, 2006
    #7
  8. dlugi

    dlugi Guest

    Another doubt is does RMI guarantee that the method of remote object can
    be invoked only by one client??

    Thnak you in advance
    dlugi, Oct 3, 2006
    #8
  9. "dlugi" <> wrote in message
    news:efuavo$cot$...
    > Hi!!
    >
    > I would like to synchronize access to one resource with two different
    > applications working in two virtual machines. Is there some technology
    > which enable to block access to resources (e.g. file, network etc) -
    > something like global semaphore.
    >
    > I consider to use JavaSpaces but this mechanism is very slow.
    > So, has anybody similar problem??


    Before you begin I think you first have to say what the resource is and how
    you plan to access it from two different JVM. If the resource is a file
    (something outside the JVM) and you just need a global lock you can use a
    TCP port. The code for accessing the file first tries to allocate a server
    port for a high number. If the access succeeds, you get to use the file.
    When you're done, release the port. If the port is already allocated, wait
    a little while and try again.

    If the resource is some Java thing, you're better off with RMI, which does
    not have to have a big overhead. There are techniques for exporting objects
    with just a few lines of code (I've posted some here before.)

    Matt Humphrey http://www.iviz.com/
    Matt Humphrey, Oct 4, 2006
    #9
  10. dlugi

    Nigel Wade Guest

    dlugi wrote:

    > Another doubt is does RMI guarantee that the method of remote object can
    > be invoked only by one client??
    >


    RMI doesn't, no (the opposite, in fact).

    But your implementation of the remote interface can impose whatever restrictions
    and limitations on the clients it wishes.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Oct 4, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rog
    Replies:
    1
    Views:
    378
    Eric Marvets
    May 22, 2004
  2. Christopher D. Wiederspan

    Synchronizing ASP.NET Content Across WebFarm

    Christopher D. Wiederspan, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    448
    Yan-Hong Huang[MSFT]
    Aug 1, 2003
  3. AbraKadabra
    Replies:
    11
    Views:
    558
    Wibble
    Sep 23, 2005
  4. Russell E. Owen
    Replies:
    0
    Views:
    688
    Russell E. Owen
    Sep 8, 2006
  5. sosecret2006
    Replies:
    0
    Views:
    487
    sosecret2006
    Dec 26, 2006
Loading...

Share This Page