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 / Virtual Machine / August 2003

Tip: Looking for answers? Try searching our database.

Creating a mutex

Thread view: 
Qaurk Noble - 12 Aug 2003 01:29 GMT
Hello all,

Does anyone know how I can create a mutex to control access to a shared
resource on one computer?

Regards,
Q. Noble
Chris Smith - 12 Aug 2003 02:31 GMT
> Does anyone know how I can create a mutex to control access to a shared
> resource on one computer?

In the Java VM?  Each object has a monitor associated with it, which can
be used as a recursive mutex.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Shripathi Kamath - 12 Aug 2003 07:13 GMT
> Hello all,
>
[quoted text clipped - 3 lines]
> Regards,
> Q. Noble

It depends on where you want to control access from:

1.  All clients in a single JVM -- that is all clients of that shared
resource have their lifecycles within a single JVM

or

2.  The clients are in different JVMs.
(or)
2b.  The clients are different entities, at least one of which is not even a
JVM.

1. is the easiest because any object can be used as a mutex.  If the shared
resource is represented by an Object, simply synchronizing around it will do
the trick.

2 and 2b. require that you use some OS specific synchronization resource.
For example, you can use a UDP or a TCP socket which is bound to a
particular port as a mutex.  To gain control of the shared resource, a
client must gain control of the mutex first.  In this case, this can be done
by opening a socket at a chosen port number. If the client suceeds in doing
so, it can assume access to the shared resource.  When done, it closes the
socket.  Other clients can then make use of the shared resource.

Of course, the above are simplistically stated, but I hope they give you
some ideas.

HTH,

Signature

Shripathi Kamath
NETAPHOR SOFTWARE INC.
http://www.netaphor.com

Jim Hansson - 12 Aug 2003 22:32 GMT
>> Hello all,
>>
[quoted text clipped - 33 lines]
>
> HTH,

for 2 and 2b you could setup the shared resource to be a remote object with
RMI, should that not solv it?

Jim


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.