[TvR] -=CyRuS=-
30-11-2000, 23:35
lo all, dunno if anyone can help me but i have a prob compiling a semaphore class in java.
This is the code for the class:
class semaphore
{
protected int value = 0;
protected semaphore() { value = 0; }
protected semaphore(int initial) { value = initial; }
public synchronized void P()
{
value--;
if (value < 0)
try { wait(); } catch( InteruptedException e) {}
}
public synchronized void V()
{
value++; if (value <= 0) notify();
}
}
and these are the error messages i get:
semaphore.java:17: exception java.lang.InteruptedException must be caught, or it must be declared in the throws clause of this method.
try { wait(); }
^
catch( InteruptedException e) {}
semaphore.java:17: Class InteruptedException not found in type declaration.
try { wait(); }
catch( InteruptedException e) {}
^
2 errors
If anyone has any ideas i cant express how much i would appreciate the help. Tryin to do a project for 3rd year of degree and its got to done in a week.
programmin - dont ya just love it! :)
cheers anyway all who have a look
[TvR]-=CyRuS=- (Marcus)
lol, im so desparate for help i even put my real name, thought it might make it a bit more personal.
This is the code for the class:
class semaphore
{
protected int value = 0;
protected semaphore() { value = 0; }
protected semaphore(int initial) { value = initial; }
public synchronized void P()
{
value--;
if (value < 0)
try { wait(); } catch( InteruptedException e) {}
}
public synchronized void V()
{
value++; if (value <= 0) notify();
}
}
and these are the error messages i get:
semaphore.java:17: exception java.lang.InteruptedException must be caught, or it must be declared in the throws clause of this method.
try { wait(); }
^
catch( InteruptedException e) {}
semaphore.java:17: Class InteruptedException not found in type declaration.
try { wait(); }
catch( InteruptedException e) {}
^
2 errors
If anyone has any ideas i cant express how much i would appreciate the help. Tryin to do a project for 3rd year of degree and its got to done in a week.
programmin - dont ya just love it! :)
cheers anyway all who have a look
[TvR]-=CyRuS=- (Marcus)
lol, im so desparate for help i even put my real name, thought it might make it a bit more personal.