JavaScript手册 
目录
此参考中包含
的内容
轻松上手
简介
操作符
语句
核心
文档
窗口
表单
浏览器
事件和
事件句柄
LiveWire
数据库服务
进程管理服务
实用工具
全局函数
LiveConnect
的Java包
索引
 
 
【目录】 【上一页】 【下一章】 【索引】

Lock

Provides a way to lock a critical section of code.

服务器端对象
实现版本 Netscape Server 3.0

创建源

The Lock constructor:

Lock();

参数

无。

Failure to construct a new Lock object indicates an internal JavaScript error, such as out of memory.

方法概览

lock Obtains the lock.
isValid Verifies that this Lock object was properly constructed.
unlock Releases the lock.

参看

project.lock, project.unlock, server.lock, server.unlock

方法

语法

lock

Obtains the lock. If someone else has the lock, this method blocks until it can get the lock, the specified timeout period has elapsed, or an error occurs.

方法源 Lock
实现版本 Netscape Server 3.0

语法

lock(timeout)

参数

timeout An integer indicating the number of seconds to wait for the lock. If 0, there is no timeout; that is, the 方法 waits indefinitely to obtain the lock. The default value is 0, so if you do not specify a value, the 方法 waits indefinitely.

返回

True if it succeeds in obtaining the lock within the specified timeout. False if it did not obtain the lock.

描述

You can obtain a lock for an object to ensure that different clients do not access a critical section of code simultaneously. When an application locks an object, other client requests must wait before they can lock the object.

Note that this mechanism requires voluntary compliance by asking for the lock in the first place.

参看

Lock.unlock, Lock.isValid, project.lock, server.lock

isValid

Verifies that this Lock object was properly constructed.

方法源 Lock
实现版本 Netscape Server 3.0

语法

isValid()

参数

无。

返回

True, if this object was properly constructed; otherwise, false.

描述

It is very rare that your Lock object would not be properly constructed. This happens only if the runtime engine runs out of system resources while creating the object.

示例

This code creates a Lock object and verifies that nothing went wrong creating it:

// construct a new Lock and save in project
project.ordersLock = new Lock();
if (! project.ordersLock.isValid()) {
   // Unable to create a Lock. Redirect to error page
   ...
}

参看

Lock.lock, Lock.unlock

unlock

Releases the lock.

方法源 Lock
实现版本 Netscape Server 3.0

语法

unlock()

参数

无。

返回

False if it fails; otherwise, true. Failure indicates an internal JavaScript error or that you attempted to unlock a lock that you don't own.

描述

If you unlock a lock that is unlocked, the resulting behavior is undefined.

参看

Lock.lock, Lock.isValid, project.unlock, server.unlock


【目录】 【上一页】 【下一章】 【索引】

回页面顶部