Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Synchronizing access to resources in Java

Thread view: 
dlugi - 03 Oct 2006 19:43 GMT
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.
opalpa@gmail.com opalinski from opalpaweb - 03 Oct 2006 19:55 GMT
How about putting the resource behind RMI?

Perform synchronize in RMI call.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
dlugi - 03 Oct 2006 20:08 GMT
opalpa@gmail.com opalinski from opalpaweb napisał(a):
> How about putting the resource behind RMI?
>
[quoted text clipped - 3 lines]
> opalpa@gmail.com
> 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
opalpa@gmail.com opalinski from opalpaweb - 03 Oct 2006 20:27 GMT
> 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
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
dlugi - 03 Oct 2006 20:36 GMT
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."
opalpa@gmail.com opalinski from opalpaweb - 03 Oct 2006 21:05 GMT
> "Advantages of Dynamic Code Loading
> One of the central and unique features of RMI is its ability to download
[quoted text clipped - 8 lines]
> 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
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
dlugi - 03 Oct 2006 23:25 GMT
opalpa@gmail.com 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
[quoted text clipped - 7 lines]
> opalpa@gmail.com
> 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 - 03 Oct 2006 23:57 GMT
Another doubt is does RMI guarantee that the method of remote object can
be invoked only by one client??

Thnak you in advance
Nigel Wade - 04 Oct 2006 10:03 GMT
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Matt Humphrey - 04 Oct 2006 01:45 GMT
> Hi!!
>
[quoted text clipped - 5 lines]
> 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 matth@ivizNOSPAM.com http://www.iviz.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.