Multiple Thread access
If multiple threads are accessing a shared resource,
I am using the wait() and notifyAll() methods for
interthread communications.
My query is:
Is the thread that has now got the Object's monitor
takes a long time to do a processing or encounters
an error,what happens to the other threads waiting
in the queue?
How long will the other threads wait for?
Is there a solution to the above problem?
Thanks
But then,if the other threads are waiting for the lock to be released,and the thread that has acquired a lock, has a problem, then is therea way around it rather than the other threads waiting?
> But then,if the other threads are waiting for the> lock to be released,> and the thread that has acquired a lock, has a> problem, then is there> a way around it rather than the other threads waiting?Nope
To get above this problem, if I create a Thread Pool
to process incoming requests, and lets suppose that
Thread 1(T1) is processing Request 1(R1),
and T2 is processing R2 and so on.
If T1 encounters a problem, but T2 has successfully processed T2,
then isnt this a better way for the problem where all threads are
waiting ?
What you should be looking at is locking the resource for the minumum necessary portion of the processing. How well you can do this, of course, rather depends on the nature of the resource we're talking about.
You may be able to buffer access with queues, for example, doing all the actual handling of the resource with one thread.