aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes THREAD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "THREAD" Watch "THREAD" New topic
Author

THREAD

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Source: Devaka Cooray's Exam Simulator.




Why is main not completing its execution??
What does Line1 signify?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Have you tried to run it because i'm getting a java.lang.IllegalMonitorStateException.
That's because the notify statement must be in synchronized code.

Read about interrupts here


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Ok..that means the Thread refernced by t is never notified, so it will never terminate.

But a.interrupt() dosent make any difference right?
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Main is terminating but the thread you have started that is not terminating.
As thread t has called wait on object of A means on a.



SCJP 6
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The program is terminated because an exception is thrown.
Try putting the notifyAll in a synchronized block.
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
How can t be notified???

synchronized(this)// dosent work inside main, so what should be done.

I know its a silly one..but cant figure it out.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

synchronized(t)
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952


Do this.
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Thanks..wouter.
Actually i get confused with Thread questions to such an extent that I actually forget Thread basics.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952


Problem is here also Abhi, you have to synchronize on this also, to run it perfectly.


And than you have to modify main also.


a.interrupt(); will do nothing. As thread running is referenced by thread t. It is just a tricky part to confuse you.
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Thanks . punit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: THREAD