File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does this program fulfill Exercise 9-2 in K and B SCJP study guide? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Does this program fulfill Exercise 9-2 in K and B SCJP study guide?" Watch "Does this program fulfill Exercise 9-2 in K and B SCJP study guide?" New topic
Author

Does this program fulfill Exercise 9-2 in K and B SCJP study guide?

Ted North
Ranch Hand

Joined: Jan 02, 2012
Posts: 103



Requirements are:

1. create a class and extend the Thread class.
2. Override the run() method of Thread. This is where the synchronized block of code will go.
3. For our three thread objects to share the same object, we will need to create a constructor that accepts a StringBuffer object in the argument.
4. The synchronized block of code will obtain a lock on the StringBuffer object from step 3
5. Within the block, output the StringBuffer 100 times (i only output 10 times so i could read all the output in the shell) and then increment the letter in the StringBuffer. You can check
Chapter 6 for StringBuffer methods that will help with this.
6. Finally, in the main() method, create a single StringBuffer object using the letter A, then create three instances of our class and start all three of them (i also named the threads so the output makes more sense to me).

i humbly offer this hilarious picture for the end-users that would appreciate it; all others please do not look below this sentence.

Ted North
Ranch Hand

Joined: Jan 02, 2012
Posts: 103

bump

- does no one have any thoughts on this?

- java_ranch its time to saddle up and un-holster that keyboard.


 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Does this program fulfill Exercise 9-2 in K and B SCJP study guide?
 
Similar Threads
Problem with excirse 9-2
Threads: synchronizing a block of code (K&B 1.5)
Excercise 9-2
Threads - K&B Exercise 9-2 -
Threads and synchronisation