Aparna Misri

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

Recent posts by Aparna Misri

Hey Ankit,


- Aparna
15 years ago
Even I can see that its for $ 49.95.
Its showing me that its for $ 49.95.
Hi Ankit,
Can you please tell me .. What is the cost of wizlabs 5.0 in Indian Rupees.
Because on site cost is around 5000 rupess (99.95$) but my friends were telling me that it costs only 700 rupess.

Thanks for replying Ankit. It means that if we are waiting on someother object (other then thread object)wait will not get notified . Its will continue to remain in waiting state. Please correct me if I am wrong.
Hi Ankit,

What is this "Master Exam"?
Also All the best for the exam

Hi All,

I have a doubt in Threads. What happens when a thread does not call notify()? Yestarday I had read in one of the posts that if a thread does not call notify(), thread can wakeup itself in such a condition(But this behavior is not guranteed). But when I was solving question from K&B book chapter 'Threads' question number 9 as given below. The explination given is "there will be no return from the wait call because
no other thread will notify the main thread". Can anybody please tell me which one is the correct answer.

Given the following
1. public class WaitTest {
2. public static void main(String [] args) {
3. System.out.print("1 ");
4. synchronized(args){
5. System.out.print("2 ");
6. try {
7. args.wait();
8. }
9. catch(InterruptedException e){}
10. }
11. System.out.print("3 ");
12. } }
What is the result of trying to compile and run this program?
A. It fails to compile because the IllegalMonitorStateException of wait() is not dealt
with in line 7.
B. 1 2 3
C. 1 3
D. 1 2
E. At runtime, it throws an IllegalMonitorStateException when trying to wait.
F. It will fail to compile because it has to be synchronized on the this object.

Thanks Harvinder and Rekha .. I got it
I am really very confused now . Now check out this example from K&S book

1. class Reader extends Thread {
2. Calculator c;
4. public Reader(Calculator calc) {
5. c = calc;
6. }
8. public void run() {
9. synchronized(c) {
10. try {
11. System.out.println("Waiting for calculation...");
12. c.wait();
13. } catch (InterruptedException e) {}
14. System.out.println("Total is: " + c.total);
15. }
16. }
18. public static void main(String [] args) {
19. Calculator calculator = new Calculator();
20. new Reader(calculator).start();
21. new Reader(calculator).start();
22. new Reader(calculator).start();
23. calculator.start();
24. }
25. }
27. class Calculator extends Thread {
28. int total;
30. public void run() {
31. synchronized(this) {
32. for(int i=0;i<100;i++) {
33. total += i;
34. }
35. notifyAll();
36. }
37. }
38. }

According to Mani's example ,I think, instead of doing c.wait()it should be calculater.wait because other threads are telling caculator thread to finish the work and then notify

Please reply I am getting confused

[ November 25, 2008: Message edited by: Aparna Misri ]
Thanks Ankit and Mani..... I have got it but still scared of this topic
But I think only E should be the answer because 't' will sleep so the main thread will get executed so 'pre ' gets printed. Because of t.join , first 't' will run so 'in' gets printed and then post will get printed.

please explain me

Hi All,

I am not able to understand 'notify' and 'wait' , can anybody please emplain me witha proper example.Consider the below example.this example is from K&B book Chapter threads and also explain me what do we mean by these lines from the book " For a thread to call wait() or notify(), the thread has to be the owner of the lock for that object.When the thread waits, it temporarily releases the lock for other threads to use, but
it will need it again to continue execution."

class ThreadA {
public static void main(String [] args) {
ThreadB b = new ThreadB();

synchronized(b) {
try {
System.out.println("Waiting for b to complete...");
} catch (InterruptedException e) {}
System.out.println("Total is: " + b.total);

class ThreadB extends Thread {
int total;

public void run() {
synchronized(this) {
for(int i=0;i<100;i++) {
total += i;

Can anybody please explain me the flow with proper explaination.

If I replace "total>30" with "total<30" in the same question what will be the output.