This topic is 4611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999985
×