Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Synchronizing access to resources in Java

Reply
Thread Tools

Synchronizing access to resources in Java

 
 
dlugi
Guest
Posts: n/a
 
      10-03-2006
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.
 
Reply With Quote
 
 
 
 
opalpa@gmail.com opalinski from opalpaweb
Guest
Posts: n/a
 
      10-03-2006
How about putting the resource behind RMI?

Perform synchronize in RMI call.

Opalinski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.geocities.com/opalpaweb/

 
Reply With Quote
 
 
 
 
dlugi
Guest
Posts: n/a
 
      10-03-2006
(E-Mail Removed) opalinski from opalpaweb napisał(a):
> How about putting the resource behind RMI?
>
> Perform synchronize in RMI call.
>
> Opalinski
> (E-Mail Removed)
> 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
 
Reply With Quote
 
opalpa@gmail.com opalinski from opalpaweb
Guest
Posts: n/a
 
      10-03-2006

>
> 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
(E-Mail Removed)
http://www.geocities.com/opalpaweb/

 
Reply With Quote
 
dlugi
Guest
Posts: n/a
 
      10-03-2006
I found it on http://java.sun.com/docs/books/tutor.../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."
 
Reply With Quote
 
opalpa@gmail.com opalinski from opalpaweb
Guest
Posts: n/a
 
      10-03-2006

> "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
(E-Mail Removed)
http://www.geocities.com/opalpaweb/

 
Reply With Quote
 
dlugi
Guest
Posts: n/a
 
      10-03-2006
(E-Mail Removed) 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
> (E-Mail Removed)
> 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 .
 
Reply With Quote
 
dlugi
Guest
Posts: n/a
 
      10-03-2006
Another doubt is does RMI guarantee that the method of remote object can
be invoked only by one client??

Thnak you in advance

 
Reply With Quote
 
Matt Humphrey
Guest
Posts: n/a
 
      10-04-2006

"dlugi" <(E-Mail Removed)> wrote in message
news:efuavo$cot$(E-Mail Removed)...
> 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 (E-Mail Removed) http://www.iviz.com/


 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      10-04-2006
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 : (E-Mail Removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing access to static variables sosecret2006 Java 0 12-26-2006 08:16 PM
py2app question: Resources/Python -> Resources/lib/python2.4 Russell E. Owen Python 0 09-08-2006 08:08 PM
Counting (and synchronizing) resources AbraKadabra Java 11 09-23-2005 02:08 AM
Synchronizing 2 Processes to access a text file simultaneously arvind MCAD 0 01-13-2005 10:02 AM
Synchronizing project files work and home. How? Rog ASP .Net 1 05-22-2004 02:18 AM



Advertisments