• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One servlet performing many tasks

 
R Reus
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a servlet (/data) which performs a lot of tasks. These
are differentiated by a parameter called "action". So this
servlet is called in the following ways:
/data?action=1
/data?action=2
/data?action=3
etc.
In terms of performance, is this a good way to build a web
app or is it better to write several servlets that each
perform one task?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In terms of performance it makes absolutely no difference as long as you coded with good practice.

Each request gets its own Thread so the only possibility of interference would be if you used synchronized code blocks which would permit only one thread at a time. Right off hand I can't think of any reason this would be necessary.

You should be worrying first and foremost about the clarity of your code, not chasing hypothetical performance tricks.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:You should be worrying first and foremost about the clarity of your code, not chasing hypothetical performance tricks.


Quoted for emphasis.

Ganging all the functionality into a single servlet sounds like a nightmare. Follow good coding practices.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In terms of design, it's a very common practice to use a Front Controller, where a single servlet accepts requests. However, a well-designed front controller delegates any "tasks" to helper objects, and sticks to handling incoming requests.

That being said, it's more about designing clear code (joining the chorus here), and probably has little impact on performance until you're chasing bugs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic