aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question 19 in mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question 19 in mock exam" Watch "Question 19 in mock exam" New topic
Author

Question 19 in mock exam

L. Wei
Ranch Hand

Joined: May 01, 2008
Posts: 37
A Classic tag handler exists in legacy code. The author wrote a handler that evaluates its tag body a hundred times, to be used in testing other tags that produce random content.

Given

What is incorrect about the code?
A. Tag handlers are not thread safe, so the iterationCount can become out of sync if multiple users are reaching the page at the same time.
B. The doAfterBody method is never being called because it is not part of the tag handler lifecycle. The developer should have extended the IterationTagSupport class to include this method in the lifecycle.
C. The doTag method should be doStartTag. As written, the default doStartTag of TagSupport is called which simply returns SKIP_BODY, causing doAfterBody to never be called.
D. When doAfterBody returns EVAL_BODY_AGAIN the doTag method is called again. The doTag method resets iterationCount to 0, resulting in an infinite loop and a java.lang.OutOfMemoryError is thrown.

The Final exam answer in the book gives C, but I selected A and C.
This question is regarding the classic tag support. I know simple tag does not reuse tags, but classic tag dose. I ever wrote a snippet code with or without reset of the counter instance variable. The test confirms me that the classic tag reuse the same instance of the tag and keep the status of the instance variable in the tag.

Then why A is incorrect in the question? Thanks.


SCJP SE 6.0, SCWCD J2EE 5
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3177
    
  47

Where is this question from? (please QuoteYourSources).


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
L. Wei
Ranch Hand

Joined: May 01, 2008
Posts: 37
The question is from Head First Servlet and JSP final mock exam.

Devaka Cooray wrote:Where is this question from? (please QuoteYourSources).
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Yes instances of classic tags are reused, but they are not used to serve two requests at the same time. At a time, an instance of a classic tag will serve only one request. The container maintains a pool of instances of classic tags. When an instance of a classic tag is serving a request, its removed from that pool and returned to the pool when it finishes serving the request. Because of this reason, iterationCount is set to 0 inside of the doTag method instead of initializing it with its declaration...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
rich dubois
Greenhorn

Joined: Feb 16, 2010
Posts: 20
Hi Ankit, thanks!

Great answer and it makes a lot of sense. It is something that has been bothering me since I read about these, I should have asked myself.

David, thanks for asking!
L. Wei
Ranch Hand

Joined: May 01, 2008
Posts: 37
Thanks Ankit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question 19 in mock exam