Multithreading in Java | #51 | ReentrantLock with Condition Interface | newcondition() Method

preview_player
Показать описание

Watch the complete web series "Java & Web" on YouTube. It's complete, comprehensive and conceptual.

Follow me on:

#JavaAndWeb #MultithreadingInJava #OCJP #SCJP #javatutorialforbeginners #javainterviewquestionsandanswersforfreshers #javainterviewquestionsandanswers #javaprogramming

Codes: note - Angled Brackets are not allowed in the video description.

class Shared
{
private int i =0;
void add()
{
i=i+1;
}
void sub()
{
i=i-1;
}
int currentValue()
{
return i;
}
}

class Check
{
public static void main(String[] args)
{
ReentrantLock l = new ReentrantLock();
Shared s = new Shared();
MyThread t1 = new MyThread("t1",l,s,inc,dec);
MyThread t2 = new MyThread("t2",l,s,inc,dec);
}
}

public class MyThread extends Thread
{
ReentrantLock lock = null;
Shared s = null;
Condition inc = null;
Condition dec = null;

public MyThread(String name, ReentrantLock lock, Shared s, Condition inc, Condition dec)
{
super(name);
this.s=s;
}


public void increase() throws Exception
{
{
{
}
{
}
}
}

public void decrease() throws Exception
{
{
{
}
{
}
}
}

public void run()
{
try
{
{
increase();
}
{
decrease();
}
}
}
}
Рекомендации по теме
welcome to shbcf.ru