Ravi Kiran V wrote:Ok thanks , then what is the appropiate way to update the cache .
3)I dont know if this question is related to threads, i thought it might be achieved through threads,
If two persons at the same time are trying to buy ticket for the same seat in a Airplane? How to avoid this situation and not let the seat become blocked?
pete reisinger wrote:
synchronized method is the same as synchronized block on "this":
I have a class (say class 'A' ) which has two methods [ m1() and m2() ] both are synchronised.
Is it possible to call m1() and m2() of the same object of class 'A', by two separate threadts 't1' and 't2' concurrently:
t1.m1()
t2.m2()
I am doing this because, watching the Socket class implementation, nor the status variable "connected" is not volatile, nor is setted in a synchronized block, so I thought that if 2 threads try to check the status of the socket, one could read a stale value of the "connected" boolean.
This exact functionality is already available -- see the java.util.concurrent.CountDownLatch class. Using this class, the 10th thread simply calls the await() method, while the other 9 calls the countdown() method (upon completion).