Ashok Iraveni

Greenhorn
+ Follow
since Jul 27, 2012
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 Ashok Iraveni

Here you are not assigning the values in your input method, you are creating two more local method variable which are having method scope.

You are not assigning your instance variables any where in your code, int instance variables by default will be assigned to zeros ,that is what printing in your output.

To make it work:

void input()
{
d=10; // remove int keyword
e=54; //remove int keyword
}
8 years ago

ashwin bhawsar wrote:I have a Counter Class with two methods : increaseCount() and decreaseCount().
I also have two threads. Thread_1's run calls the increaseCount() and Thread_2's run calls the decreaseCount().
Both threads share a common instance of Counter class.

Now, what i want is Thread_2 to execute decreaseCount() only after Thread_1 has finished executing the increaseCount().
( i know this can be done with join() method, but want to achieve the same thing using wait() and notify() )

I have made the Thread_2 to wait till the Thread_1 completes its execution. After Thread_1 finishes its execution it call the notify() on the shared object.
But the problem is that Thread_2 keeps on waiting even after Thread_1 notifies it. Why ? am i missing something ?






Hi Ashwin

Use one boolean flag in COunter class,

like

boolean hasIncreased = false ;

and check this flag before waiting in Decrement logic instead waiting all the time.

thanks