java.lang.Object
nl.tudelft.simulation.language.concurrent.Monitor

public final class Monitor extends Object
Monitor class. In the Java programming language there is a lock associated with every object. The language does not provide a way to perform separate lock and unlock operations; instead, they are implicitly performed by high-level constructs that always arrange to pair such operations correctly. This Monitor class, however, provides separate monitorenter and monitorexit instructions that implement the lock and unlock operations. The class is final for now, as it is not the idea that the class should be extended. It has only static methods.

Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Peter H.M. Jacobs, Alexander Verbraeck
  • Method Details

    • lock

      public static void lock(Object object)
      locks an object for the current thread.
      Parameters:
      object - Object; the object to lock
    • lock

      public static void lock(Object object, Thread requestor)
      locks an object for the given requestor.
      Parameters:
      object - Object; the object to lock.
      requestor - Thread; the requesting thread.
    • unlock

      public static void unlock(Object object)
      unlocks an object locked by the current Thread.
      Parameters:
      object - Object; the object to unlock
    • unlock

      public static void unlock(Object object, Thread owner)
      unlocks an object locked by owner.
      Parameters:
      object - Object; the object to unlock.
      owner - Thread; the owning thread.