Bobby Oberoi

Greenhorn
+ Follow
since Dec 14, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bobby Oberoi

This might sound absurd guys.. But i was get varying results on my Windows box and i am getting as expected results on my Linux box..

don't know what to say...
14 years ago
Thanks for the response..

Ya when thread goes to sleep it does allow other thread to work on thier stuff but that does not mean it relinquishes its lock

Javadoc:
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.

Please let me know if i am wrong here.. (Anyways my real problem is not related to sleeping of thread.. i just mocked that thing up so it would return after await time has elapsed)

My basic question is:
If ThreadA is waiting for 10 seconds..

Second 0: ThreadA:await..releases the lock
Second 1:ThreadB acquires it and starts working on it
Second 10: Time elapsed for ThreadA to wait but can't reaquire the lock as ThreadB is working on it..
Second 20: ThreadB finishes its work, does signalAll and releases the lock
Second 21: ThreadA awakes..gets the lock... now as per Javadoc.. if time elapses it should return false as in this case... but it also returns true sometimes...

Hope my question ain't stupid..
14 years ago
Alright.. Hello everyone..

Its a very simple code.. Two threads.. One puts and one takes out from the array.. Both wait on size condition of being full and empty respectively

Size of Array is 2
Now the question is when i try to put 3rd element.. it waits(100 ms) on it as there is no space..
Now Thread2 runs and pulls out a value..I have made it to sleep for 300 ms before signaling..

When Put will acquire the lock again.. The Return value should be false.. but its true in many cases... Can't figure out why ??

JavaDoc of await
await
boolean await(long time,
TimeUnit unit)
throws InterruptedException
Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses. This method is behaviorally equivalent to:

awaitNanos(unit.toNanos(time)) > 0


Parameters:
time - the maximum time to wait
unit - the time unit of the time argument
Returns:
false if the waiting time detectably elapsed before return from the method, else true



Example:




Thank you very much...(I can show the output if needed)
14 years ago