• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bump

- does no one have any thoughts on this?

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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic