1 package com.protomatter.util; 2 3 52 53 import com.protomatter.syslog.Syslog; 54 import java.util.*; 55 56 59 public class Mutex 60 { 61 private MutexObject mutex = new MutexObject(); 62 private MutexToken token = null; 63 private Thread currentThread = null; 64 65 68 public Mutex() 69 { 70 super(); 71 } 72 73 77 public void getLock() 78 { 79 try 80 { 81 token = (MutexToken)mutex.checkout(); 82 this.currentThread = Thread.currentThread(); 83 } 84 catch (Exception x) 85 { 86 Syslog.log(this, x); 87 ; } 90 } 91 92 95 public boolean isLocked() 96 { 97 return (this.currentThread != null); 98 } 99 100 104 public Thread getLockingThread() 105 { 106 return this.currentThread; 107 } 108 109 115 public void releaseLock() 116 { 117 try 118 { 119 synchronized (mutex.getSyncObject()) 120 { 121 mutex.checkin(token); 122 this.currentThread = null; 123 } 124 } 125 catch (Exception x) 126 { 127 Syslog.log(this, x); 128 ; } 131 } 132 } 133 | Popular Tags |