Aparna Misri

Ranch Hand
+ Follow
since Sep 30, 2008
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 Aparna Misri

Hey Ankit,

Congrats!!!

- 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
Aparna
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

-Thanks
Aparna
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
Aparna
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;
3.
4. public Reader(Calculator calc) {
5. c = calc;
6. }
7.
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. }
17.
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. }
26.
27. class Calculator extends Thread {
28. int total;
29.
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

-Aparna
[ 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

Thanks
Aparna
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();
b.start();

synchronized(b) {
try {
System.out.println("Waiting for b to complete...");
b.wait();
} 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;
}
notify();
}
}
}

Can anybody please explain me the flow with proper explaination.

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