import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.TimeUnit;
/**
* This class contains a main-method that demonstrates some locking-mechanism over multiple <code>Thread</code>s
*
* @author orochi-100
* @version 25.02.2020
*
*/
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello World!");
ReentrantLock lock = new ReentrantLock();
int a = 5;
for (int i = 0; i < 4; i++)
new Thread(() ->
{
System.out.println("asd");
lock.lock();
System.out.println(a + "\n");
try
{
TimeUnit.SECONDS.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
lock.unlock();
}
}).start();
}
}