Semaphore-like method in j2se 1.4 ? (FileChannel and FileLock)

Is there any way in j2SE in 1.4.2 to simulate a semaphore?

I was planning on on implementing the following

public class RynoLock()

      private int lock;
            private File file = new File("Rynolock.txt");
            private FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
          private FileLock lock;
      public RynoLock(){
      public RynoLock(int rulock){
      public synchronized void acquirerulock(){
            catch)InterruptedException ie){}
                    //Obtain lock without blocking. Method returns
                  //returns a null or throws an exception if file is locked.
                    try {
                        lock = channel.tryLock();
                         } catch (OverlappingFileLockException e) {
                        // File is already locked in this thread or vm

      public synchronized void releaserulock(){
// Release the lock

              // Close the file



but this doesn't deal well with many processes running on the same machine...  FileChannel only deals PER JVM right?
What would you suggest using?  I would love to use j2se 5.0 with the additions to concurrency and the semaphore class, but need to stick with j2se 1.4.2...  Any suggestions?  Is there any way of force releasing?  I've searchign some, but can't find anything....

serializing/deserializing an object on the server?  

Who is Participating?
actually most of the additions to 1.5's concurrency and semaphore classes were borrowed from
util.concurrency package written by Doug Lee.. he was responsible for JSR166 which brought about the improvements in Java 1.5

Semaphores are not inter-process communications - they are inter-thread (or logical thread)

It's not necessary to use 1.5 to get a semaphore - you can make one with Object.wait and Object.notify

FileLocks are only advisory and may be ignored

This will discuss semaphores:
Tommy BraasCommented:
>> but this doesn't deal well with many processes running on the same machine
If you're trying to accomplish this on the machine level, not just JVM level, then you will need native code to ensure the lock. But then only if the operating system supports it.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Sorry not help you.
ryno71Author Commented:

Thanks for the feedback anyway!  Appreciate it

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.