This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes Portals and Portlets and the fly likes Variables in Portlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Variables in Portlets" Watch "Variables in Portlets" New topic

Variables in Portlets

John Lincoln
Ranch Hand

Joined: Feb 11, 2003
Posts: 192
I have small question, can we declare variable at class level ?

Generally in servlets we don't declare instance variables.

Is the samething applies to Portlets. I am little confused. Portlets are based on portletrequest & response, not on HttpRequest and HttpResponse.

Should we not declare instance variables for portlets ? Can someone who has clear understanding explain it.

I will really appreciate your help
Ashish Sarin
Ranch Hand

Joined: Nov 20, 2000
Posts: 432
Hi John,

Your understanding is correct - portlets are like servlets and you should not declare instance variables in the portlet class. The reason is the same as in case of servlets - multiple threads might be accessing the same portlet instance.


Author of
Getting started with Spring Framework
Portlets in Action
Spring Roo 1.1 Cookbook
Portlets blogSpring Roo blog
I agree. Here's the link:
subject: Variables in Portlets