• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A Mock Question

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that the Servlet Container has just called the destroy() method of a servlet instance, which of the following statements are correct?
Select 2 correct options
a service() method of this instance has been called at least once.

b init() method of this instance has been called at least once.

c Servlet container can bring this instance back into action by calling
it's init().

d There are no container threads running over this instance's service
method.

e All threads created by this servlet are done.

I think the answer is b, e.

What do you think?

Thanks.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The Answer is d and e,

the container will compleate all the requests before calling the Destory method on serverlet instance.

Once destory method is called the servlet will be avaliable for GC. no instance will be avaliable to create the threads.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Why couldn't option b is the answer...
Actually, I am confused with b, d & e..

Can anybody justify..?
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option b is wrong. next time user send a request to the servlet. the container will create new instance for the servlet.
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think option b is also correct. As init() will has be called when container calls destroy().

Can there be any situation when a servlet's init() is not called and container calls its destory()method??
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll go for b and d....anyone to support me?? c is not correct because "Servlet container can bring this instance back into action by calling
it's init(). " the container cannot bring back the same instance when the next time it calls init(). It is alltogether a new instance...does this makes sense?? What was the answer given in the mock exam??
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jothi - I agree. Though, I'm not 100% sure to be honest.

My thinking...

a- wrong. we don't know it ever received any requests
b- right. init must be called first in the life cycle. If init wasn't called, then destroy() couldn't be called either.
c- wrong. init() is only ever called once on an instance. I guess a new instance could be created, but the question doesn't say that.
d- right. The Container shouldn't send any more threads over service() if destroy has been called. However, the question just say "just", which could mean that threads are still running over it. Just being picky!
e- wrong. I guess the instance could have created threads, and just because threads are not running upon it, doesn't mean that its threads need to die.

What did the question say were the right answers?

MG
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

i will go for d and e

I can say b is not included in answer.Because the option included AT LEAST one.Means one or more times.So this can't be the answer.

For option d.

These are from specification [p/g 28 last para]
------------------------------------------------------------------------
Before the servlet container calls the destroy method, it must allow any
threads that are currently running in the service method of the servlet to complete execution, or exceed a server-defined time limit.
---------------------------------------------------------------------

For option e.

By the time the container calls the destroy ,there are no user threads.If it is created .If there are no requests,nothing happens.

Thanks

Anil Kumar
[ June 26, 2007: Message edited by: anil kumar ]
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Man.....such kind of questions tests our english or rather the subject?
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would still argue that b is correct.

If calling destroy, we're agreed that init() has been called once.

- It has been called ONCE
- Has it been called at least ONCE? Yes. Then the answer must be true.
 
anil kumar
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Jothi

I don't know about the author who wrote that question,wants to test our english or subject.But i can say sun will definetly going to test our subject.


Thanks

Anil Kumar
[ June 26, 2007: Message edited by: anil kumar ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think b, d and e are correct.
Please refer to SRV.2.3.4.
 
Harshad Dhamorikar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think b, d and e are correct.
Please refer to SRV.2.3.4.
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic