Recommended Posts

Share on other sites
Hi,
You can replace the notifyAll() with just notify() since its expensive to notify all the threads, only 1 waiting thread should be waken. I have a textbook discussing the same problem you're facing, the reader writer problem. But since your code looks ok, I'll give you some other suggestions:

Ok, what I think you should try is everywhere you use the wait() func, rewrite it like so:
From this:
if (accessType == 1 || accessType == 2){	try	{		wait();	}	catch (InterruptedException e)	{		System.err.println("interrupted out of wait");	}		accessType = 2;}

To this:
while (accessType == 1 || accessType == 2){	try	{		wait();				accessType = 2;				break;	}	catch (InterruptedException e)	{		System.err.println("interrupted out of wait");	}}

I guess that should help it to work.

Maybe you can use a boolean dbWriting variable indicating when the database is being written to, instead of having accessType variables.

I don't mean to be a critic or anything, I'm just giving some suggestions which you can try out. Sorry if I look intimidating, but I'm not trying to be.

Let me know if any of this works.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628378
• Total Posts
2982348

• 10
• 9
• 15
• 24
• 11