1 jls.loader.provide('jls.lang.Monitor'); 2 3 jls.lang.Monitor = jls.lang.Class.create(/** @lends jls.lang.Monitor.prototype */ 4 { 5 /** 6 * Creates a monitor. A monitor provides a means to synchronize threads. 7 * 8 * @constructs 9 * @class A monitor provides a means to synchronize threads. 10 * Notification involves passing synchronization information among cooperating threads. 11 */ 12 initialize : function() { 13 this._no = new _native.core.Monitor(); 14 }, 15 /** 16 * Closes this monitor. 17 * 18 * @returns {jls.lang.Monitor} This monitor. 19 */ 20 close : function() { 21 this._no.close(); 22 return this; 23 }, 24 /* 25 * Enters the monitor. 26 * 27 * @returns {jls.lang.Monitor} This monitor. 28 */ 29 /* enter : function() { 30 this._no.enter(); 31 return this; 32 }, */ 33 /* 34 * Exits the monitor. 35 * 36 * @returns {jls.lang.Monitor} This monitor. 37 */ 38 /* exit : function() { 39 this._no.exit(); 40 return this; 41 }, */ 42 /** 43 * Causes the current thread to wait until another thread invokes the notify method of this monitor. 44 * 45 * @param {Number} [timeout] The maximum time to wait in milliseconds. 46 * @returns {jls.lang.Monitor} This monitor. 47 */ 48 wait : function(timeout) { 49 this._no.enter(); 50 this._no.wait(timeout || -1); 51 this._no.exit(); 52 return this; 53 }, 54 /** 55 * Wakes up a single thread that is waiting on this monitor. 56 * 57 * @returns {jls.lang.Monitor} This monitor. 58 */ 59 notify : function() { 60 this._no.enter(); 61 this._no.notify(); 62 this._no.exit(); 63 return this; 64 } 65 }); 66 67