!--a11y-->
Working with Locks 
To set locks, you can use the table-locking API. The Locking Adapter Service of the SAP J2EE Engine provides instances of the table-locking by using JNDI. The table-locking API is described by the interface com.sap.engine.services.applocking.TableLocking; the JNDI name is contained in the constant TableLocking.JNDI_NAME.
You can get a table-locking instance by using the following lines:

|
Context initialContext = new InitialContext(); TableLocking locking = (TableLocking) initialContext.lookup(TableLocking.JNDI_NAME); |
Locks are used in the context of transactions and connections. For all operations, the corresponding connection has to be transferred to the table-locking methods. You can get a connection from a DataSource as follows:

|
DataSource datasource = (DataSource) initialContext.lookup("jdbc/DS"); Connection connection = datasource.getConnection(); |
Connection: A connection is looked up in the JNDI. In this example, DS is the name of the DataSource.
