السلام عليكم ورحمة الله وبركاته
عندي واجب ومحتاجه مساعدتكم في تصحيح الاخطاء عندي
السؤال كالتالي
اقتباس
Consider the class below which models a product line control system. Based on the number of items on the product line conveyor, the control system should allow or prevent newer items to be added on the conveyor. This class has two methods: enter() which is invoked whenever a new item is to be added to the conveyor, and exit() which is invoked when a product is taken off the conveyor. The maximum number of products on the conveyor is limited to 100 products.
a) You are required to apply the wait-notify mechanism in order to make the class thread-safe.
b) You are required to repeat (a) using a different technique which uses the Java package java.util.concurrent.locks in order to allow multiple condition variables for different locks. Assume that you have two conditions: notFull and notEmpty.
public class ConveyorControl {
private int count;
public void enter() {
try {
count++;
} catch (Exception e) {
} finally {
}
}
public void exit(){
try {
count--;
} catch (Exception e) {
} finally {
}
}
}وهذا حلي بالنسبه للـ enter method
Public class ConveyorControl {
Private int count ;
Public Synchronized void enter(){
try{
while (count>=100)
wait();
count++;
notifyAll();
}
Catch (Exception e)
{
}
Finally
{
}والـ exit method
Public Synchronized void enter(){
try{
while (count==100)
wait();
}
Count--;
notifyAll();
}
Catch (Exception e)
{
}
Finally
{
}
وهذا بالنسبة للفقره الثانيه
import java.util.concurrent.locks.*;
public class ConveyorControl {
private int count;
Lock myLock = new ReentrantLock();
Condition notEmpty = myLock.newCondition();
Condition notFull = myLock.newCondition();
public void exit() {
myLock.lock();
try {
while (counter == 100) {
notFull.await();
}
count--;
notEmpty.signalAll();
}
catch(Exception e)
{
}
finally {
myLock.unlock();
}
}
public void subtract() {
myLock.lock();
try {
while (counter == 100) {
notEmpty.await();
}
counter--;
notFull.signalAll();
}
catch(Exception e)
{
}
finally {
myLock.unlock();
}
}
}المشكله طالب اننا نشغل الاكواد بالـ netbeans او اي مشغل اخر
وتطلعلي اخطاء كثيره
اتمنى منكم مساعدتي وتوضيح الاخطاء اللي عندي