dcsimg
how to set number of thread that can access syncronize data ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   aruna_rani
Posted On:   Monday, February 25, 2002 12:31 AM

say if 3 threads allowed to read and 4th thread should be rejected

Re: how to set number of thread that can access syncronize data ?

Posted By:   Chandra_Patni  
Posted On:   Monday, February 25, 2002 01:43 AM

You have to implement your own synchronization mechanism to do so.
A very simple implementation can be as follows. Note that you can write a lot more elegant way of doing it.

public class A {
private int count = 0;

public void method() {
if(getActiveThread() < 3) {
methodHelper();
}
}

private synchronized void methodHelper() {
i++;
// method implementation here.
i--;
}

private synchronized int getActiveThread() {
return i;
}
}
About | Sitemap | Contact