Harsh Singh

+ Follow
since Dec 08, 2004
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 Harsh Singh

There is nothing erratic here.
B thread is not guaranteed to be running when A thread is running. Therefore you get two different results depending upon if B is running or not when A executes B.join() statement.
If B is running then A waits for B to end otherwise A finishes without waiting.
Remember that by default you have a thread called main. The main thread here will create Master object m and will run m.go().
Once inside m.go() a new thread t1 is created. Now we have main thread which is at the while(bContinue==false) statement and t1 thread running the run method of Slave.
The t1 thread operates on the Slave object s. Since the run method of slave is synchronized therefore the thread t1 has a lock on object s and main thread cannot run any other synchronized methods of s until t1 is done with the run method.
Since run method has an infite loop t1 will never release the lock of s and main will forever get stuck at s.setPrice(200) line. That's why you keep seeing repeated 100 but no 200.

Hope this helps.

Try to use the links at the top of the forum and search for your questions.
Hope this helps.
I totally agree. Read K&B if you can find it. The book gives you valuable tips and prepares you well for the exam. IMO JLS should be used more like a reference document. Moreover, reading K&B would be more enjoyable then JLS .

Hope this helps and good luck!
[ January 17, 2005: Message edited by: Harsh Singh ]
First of all the method eat is not overridden but overloaded in this example.
Class cattle has two versions of eat: eat(Mammal) and eat(Cattle)
Class Horse has three versions of eat: eat(Mammal), eat(Cattle) and eat(Horse).

now for the line c.eat(h);
At the compile time it binds it to eat(Mammal) of the Cattle class.
At the runtime it runs the eat(Mammal) of the object Horse.

Hope that helps (& hope I am right ;-) )
There was a survey asking about your expertise level. Without wasting much time I quickly checked expert level for all the questions. It would be unfair if the exam questions changed based on the answers to this survey. As far as I remember clock did not start with the survey.
Next was supposed to be the actual exam, Clock started but it first prompted for some disclaimer stuff and "I agree/I don't agree" type of questions. It did take few seconds away from the allotted time.
Overall I would say there was just enough time to answer all the questions and review some of the ones you have doubts about.
Good luck!
19 years ago
I thought I was too old to study, but I did it.

Thanks to Kathy & Bert for their excellent book. Everything on the exam is nicely covered in their book. I read it twice to get a good handle on the topics. Re-read all the "exam watch" alerts day before the exam.

I also read Khalid Mughal's book and did Whizlab mock exams which come with the book.
I took tons of freely available mock exams like:
The JavaRanch Rules Round-up
Marcus Green's Mock Exam
Bill Brogden's Mock Exam
Also used Corey McGlone's Blog "The SCJP Tipline".

Finally thanks to JavaRanch, It rocks!
[ January 03, 2005: Message edited by: Harsh Singh ]
19 years ago
Threads should run something like this: (Not sure if this will display right)

Main-------23 (start t2)-24-----13----(Start 2nd t2)--14 (Done)
1st t2-----------Starts ---21(Blocked)---------------------------------------(Resumes) 22
2nd t2----------------------------------------Starts-----------11(Blocked)--(Resumes) 12

We can see that Main and first t2 thread are running parallal for a while which would give different combinations of 24 13 14 and 21.
One thing can be concluded for sure that 22 & 12 will print only after 14 is printed. 14 marks the end of the main thread and 22 and 12 are ends of the t2 thread instances.
[ December 27, 2004: Message edited by: Harsh Singh ]

setPrice() would be called by the go() method in Master, except that execution of go() never gets past t1.start(), which lets run() go into a loop while holding the lock.

The main thread will actually go past t1.start() and the while(bContinue==false) loop but will get stuck at the s.setPrice(200) because thread t1 holds the lock on Slave object 's' while executing run method.
I failed your SCJP test. I think I am gonna skip the Self-Esteem Test for some other day.
It will be nice though if you could give "back" and "forward" buttons and also the answers at the end of the test.
Thanks for the effort.