Class LockService
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
잠금서비스
코드 섹션에 대한 동시 액세스를 방지합니다. 이는 공유 리소스를 수정하는 여러 사용자 또는 프로세스가 있고 충돌을 방지하려는 경우에 유용할 수 있습니다.
자세한 문서
getDocumentLock()
현재 문서의 사용자가 코드 섹션을 동시에 실행하지 못하도록 하는 잠금을 가져옵니다. 문서 잠금으로 보호되는 코드 섹션은 서로 다른 문서의 컨텍스트에서 실행되는 스크립트 인스턴스에서 동시에 실행할 수 있지만, 특정 문서에 대해 한 번만 실행할 수 있습니다. Lock.tryLock(timeoutInMillis)
또는 Lock.waitLock(timeoutInMillis)
가 호출될 때까지는 실제로 잠금이 획득되지 않습니다. 이 메서드가 포함된 문서의 컨텍스트 외부에서 호출되면 (예: 독립형 스크립트 또는 웹앱에서) null
이 반환됩니다.
리턴
Lock
: 스크립트 및 현재 문서에 범위가 지정된 잠금 또는 독립형 스크립트 또는 웹 앱에서 호출된 경우 null
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eLockService\u003c/code\u003e prevents concurrent access to shared resources in Apps Script, avoiding collisions when multiple users or processes modify them.\u003c/p\u003e\n"],["\u003cp\u003eIt offers three types of locks: \u003ccode\u003egetDocumentLock()\u003c/code\u003e, \u003ccode\u003egetScriptLock()\u003c/code\u003e, and \u003ccode\u003egetUserLock()\u003c/code\u003e, each with different scopes of access restriction.\u003c/p\u003e\n"],["\u003cp\u003eThese locks are acquired using \u003ccode\u003eLock.tryLock(timeoutInMillis)\u003c/code\u003e or \u003ccode\u003eLock.waitLock(timeoutInMillis)\u003c/code\u003e methods for controlled access to critical code sections.\u003c/p\u003e\n"],["\u003cp\u003eEach lock type returns a \u003ccode\u003eLock\u003c/code\u003e object that provides methods to manage the lock, ensuring data integrity and consistency in shared environments.\u003c/p\u003e\n"]]],[],null,["# Class LockService\n\nLockService\n\nPrevents concurrent access to sections of code. This can be useful when you have multiple users\nor processes modifying a shared resource and want to prevent collisions. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------|------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [getDocumentLock()](#getDocumentLock()) | [Lock](/apps-script/reference/lock/lock) | Gets a lock that prevents any user of the current document from concurrently running a section of code. |\n| [getScriptLock()](#getScriptLock()) | [Lock](/apps-script/reference/lock/lock) | Gets a lock that prevents any user from concurrently running a section of code. |\n| [getUserLock()](#getUserLock()) | [Lock](/apps-script/reference/lock/lock) | Gets a lock that prevents the current user from concurrently running a section of code. |\n\nDetailed documentation\n----------------------\n\n### `get``Document``Lock()`\n\nGets a lock that prevents any user of the current document from concurrently running a section\nof code. A code section guarded by a document lock can be executed simultaneously by script\ninstances running in the context of different documents, but by no more than one execution for\nany given document. Note that the lock is not actually acquired until [Lock.tryLock(timeoutInMillis)](/apps-script/reference/lock/lock#tryLock(Integer))\nor [Lock.waitLock(timeoutInMillis)](/apps-script/reference/lock/lock#waitLock(Integer)) is called. If this method is called outside of the context of a\ncontaining document (such as from a standalone script or webapp), `null` is returned.\n\n#### Return\n\n\n[Lock](/apps-script/reference/lock/lock) --- a lock scoped to the script and current document, or `null` if called from a\nstandalone script or webapp\n\n*** ** * ** ***\n\n### `get``Script``Lock()`\n\nGets a lock that prevents any user from concurrently running a section of code. A code section\nguarded by a script lock cannot be executed simultaneously regardless of the identity of the\nuser. Note that the lock is not actually acquired until [Lock.tryLock(timeoutInMillis)](/apps-script/reference/lock/lock#tryLock(Integer)) or [Lock.waitLock(timeoutInMillis)](/apps-script/reference/lock/lock#waitLock(Integer)) is called.\n\n#### Return\n\n\n[Lock](/apps-script/reference/lock/lock) --- a lock scoped to the script\n\n*** ** * ** ***\n\n### `get``User``Lock()`\n\nGets a lock that prevents the current user from concurrently running a section of code. A code\nsection guarded by a user lock can be executed simultaneously by different users, but by no\nmore than one execution for any given user. The lock is \"private\" to the user. Note that the\nlock is not actually acquired until [Lock.tryLock(timeoutInMillis)](/apps-script/reference/lock/lock#tryLock(Integer)) or [Lock.waitLock(timeoutInMillis)](/apps-script/reference/lock/lock#waitLock(Integer)) is\ncalled.\n\n#### Return\n\n\n[Lock](/apps-script/reference/lock/lock) --- a lock scoped to the script and current user"]]